How to disable django migration debug logging?

Very similar to the lafagundes question about south debugging logging , except that I don't use south - I use simple Django 1.7 migrations. I also use the django-nose test runner.

When I run manage.py test , the output of the debug log will not be removed:

 (codesy)lcrouch:codesy lcrouch$ ./manage.py test nosetests --verbosity=1 Creating test database for alias 'default'... ......E............................... ====================================================================== ERROR: test_return_state (auctions.tests.utils_tests.IssueStateTest) ---------------------------------------------------------------------- 

When I run a separate test module, for example ./manage.py test auctions.tests.utils_tests , the output of the debug log includes all lines of django.db.backends.schema: DEBUG involved in the Django migration:

 (codesy)lcrouch:codesy lcrouch$ ./manage.py test auctions.tests.utils_tests nosetests auctions.tests.utils_tests --verbosity=1 Creating test database for alias 'default'... E ====================================================================== ERROR: test_return_state (auctions.tests.utils_tests.IssueStateTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/lcrouch/code/codesy/codesy/auctions/tests/utils_tests.py", line 13, in test_return_state fake_gh_client = fudge.Fake(github_client).returns_fake().provides('get_repo').returns_fake().provides('get_issue').returns_fake().has_attr(state='open') File "/Users/lcrouch/python/codesy/lib/python2.7/site-packages/fudge/__init__.py", line 1133, in returns_fake exp = self._get_current_call() File "/Users/lcrouch/python/codesy/lib/python2.7/site-packages/fudge/__init__.py", line 765, in _get_current_call "Call to a method that expects a predefined call but no such call exists. " FakeDeclarationError: Call to a method that expects a predefined call but no such call exists. Maybe you forgot expects('method') or provides('method') ? -------------------- >> begin captured logging << -------------------- django.db.backends.schema: DEBUG: CREATE TABLE "django_migrations" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "app" varchar(255) NOT NULL, "name" varchar(255) NOT NULL, "applied" datetime NOT NULL); (params []) django.db.backends.schema: DEBUG: CREATE TABLE "django_content_type" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(100) NOT NULL, "app_label" varchar(100) NOT NULL, "model" varchar(100) NOT NULL); (params []) django.db.backends.schema: DEBUG: CREATE TABLE "django_content_type__new" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(100) NOT NULL, "app_label" varchar(100) NOT NULL, "model" varchar(100) NOT NULL, UNIQUE ("app_label", "model")); (params []) ... django.db.backends.schema: DEBUG: DROP TABLE "socialaccount_socialapp"; (params []) django.db.backends.schema: DEBUG: ALTER TABLE "socialaccount_socialapp__new" RENAME TO "socialaccount_socialapp"; (params []) 

Which really makes it difficult to return to the actual failure.

How to disable this output? Or at the level of django or nose?

+5
source share
2 answers

If you don't mind disabling migration during testing, you can do this by adding the following to your .py settings:

 TESTING = 'test' in sys.argv if TESTING: class DisableMigrations(object): def __contains__(self, item): return True def __getitem__(self, item): return "notmigrations" MIGRATION_MODULES = DisableMigrations() 

This will simply create the database at a time, instead of going through each migration.

If you want to keep migrations in tests, you can delete messages by updating the logging settings.

 TESTING = 'test' in sys.argv if TESTING: LOGGING = { 'version': 1, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'filename': '/tmp/codesy-debug.log', }, }, 'loggers': { 'django.db.backends.schema': { 'handlers': ['file'], 'propagate': True, 'level': 'INFO', }, '': { 'handlers': ['file'], 'level': 'DEBUG', } } } 
+4
source

To quickly delete log messages, you can run with:

./manage.py test --nologcapture

Messages are captured by the logcapture nose plugin , which has additional options for fine tuning. However, django-nose has an old problem , which may prevent you from using many of them from the command line. It is planned for milestone v1.4.2 , but it is overdue for a month. You can work with .noserc or nose.cfg - see nose documents for format.

+2
source

All Articles