2015-08-22 6 views
5

lafagundes question about south migration debug logging के समान, सिवाय इसके कि मैं दक्षिण का उपयोग नहीं कर रहा हूं - मैं सादा Django 1.7 माइग्रेशन का उपयोग कर रहा हूं। मैं django-nose परीक्षण धावक का भी उपयोग कर रहा हूं।मैं django माइग्रेशन डीबग लॉगिंग को कैसे अक्षम करूं?

(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) 
---------------------------------------------------------------------- 

जब मैं एक व्यक्ति के परीक्षण मॉड्यूल, जैसे, ./manage.py test auctions.tests.utils_tests चलाने के लिए, डीबग लॉगिंग उत्पादन Django में शामिल django.db.backends.schema: DEBUG लाइनों के सभी शामिल हैं:

जब मैं manage.py test चलाने के लिए, वहाँ कोई डीबग लॉगिंग उत्पादन पर कब्जा कर लिया है माइग्रेशन:

(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 []) 

जो वास्तविक विफलता का बैक अप लेने में वाकई मुश्किल बनाता है।

मैं इस आउटपुट को कैसे अक्षम कर सकता हूं? या तो django या नाक स्तर पर?

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() 

यह सिर्फ एक ही बार में डेटाबेस पैदा करेगा, बल्कि के माध्यम से कदम से:

उत्तर

4

आपने परीक्षण के दौरान माइग्रेशन अक्षम करने से परहेज नहीं करते हैं, तो आप को जोड़कर अपने settings.py को निम्न कर सकते हैं प्रत्येक माइग्रेशन।

यदि आप परीक्षणों में माइग्रेशन चलाना चाहते हैं, तो आप लॉगिंग सेटिंग अपडेट करके संदेशों को हटाने में सक्षम हो सकते हैं।

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', 
      } 
     } 
    } 
+2

धन्यवाद, लॉगिंग कॉन्फ़िगरेशन दृष्टिकोण अच्छा है। लेकिन ऐसा लगता है कि यह डीजेंगो में ही एक विकल्प होना चाहिए? – groovecoder

+0

मैंने 'लॉगिंग' सेटिंग्स को ट्वीक करने का भी अंत किया, विशेष रूप से मैंने केवल 'हैंडलर' को '[' कंसोल '] और' लेवल' '' वॉर्निंग 'पर सेट किया। –

2

जल्दी से प्रवेश संदेशों को निकालने के लिए आप के साथ चला सकते हैं:

./manage.py test --nologcapture

संदेशों nose logcapture plugin है, जो ठीक ट्यूनिंग के लिए अतिरिक्त विकल्प है द्वारा कब्जा कर लिया जा रहा है। हालांकि, django-nose में old issue है जो आपको कमांड लाइन से उन लोगों में से कई का उपयोग करने से रोक सकता है। यह milestone v1.4.2 के लिए निर्धारित है, लेकिन यह एक महीने का अतिदेय है। आप .noserc या nose.cfg फ़ाइल वाले लोगों के आसपास काम करने में सक्षम हो सकते हैं - प्रारूप के लिए nose docs देखें।

+0

यह तेज़ी से काम करता है, लेकिन मैं ** ** अन्य लॉगिंग आउटपुट को कैप्चर करना चाहता हूं। मैं सिर्फ 'DEBUG' स्तर आउटपुट नहीं चाहता हूं। – groovecoder

संबंधित मुद्दे