{"id":723,"date":"2015-06-09T21:14:46","date_gmt":"2015-06-10T03:14:46","guid":{"rendered":"http:\/\/www.crccheck.com\/blog\/?p=723"},"modified":"2015-10-11T22:21:39","modified_gmt":"2015-10-12T04:21:39","slug":"django-nose-without-django-nose","status":"publish","type":"post","link":"https:\/\/www.crccheck.com\/blog\/django-nose-without-django-nose\/","title":{"rendered":"Django Nose without Django-Nose"},"content":{"rendered":"<p><a href=\"http:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2015\/06\/tycho-brahe-avvelenamento-638x425.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-726\" src=\"http:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2015\/06\/tycho-brahe-avvelenamento-638x425-300x200.jpg\" alt=\"Tycho Brahe\" width=\"300\" height=\"200\" srcset=\"https:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2015\/06\/tycho-brahe-avvelenamento-638x425-300x200.jpg 300w, https:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2015\/06\/tycho-brahe-avvelenamento-638x425.jpg 616w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I&#8217;ve grown to dislike Django-Nose. It&#8217;s been over three months since Django 1.8 has been released and they still don&#8217;t have a release that fully supports it. These are the advantages they currently tout:<\/p>\n<ul>\n<li><span style=\"color: #808080;\">Testing just your apps by default, not all the standard ones that happen to be in INSTALLED_APPS<\/span>\n<ul>\n<li>The Django test runner has been doing this since 1.6 https:\/\/docs.djangoproject.com\/en\/1.8\/releases\/1.6\/#discovery-of-tests-in-any-test-module<\/li>\n<\/ul>\n<\/li>\n<li><span style=\"color: #808080;\">Running the tests in one or more specific modules (or apps, or classes, or folders, or just running a specific test)<\/span>\n<ul>\n<li>They all can do this, even the old Django test runner<\/li>\n<\/ul>\n<\/li>\n<li><span style=\"color: #808080;\">Obviating the need to import all your tests into tests\/__init__.py. This not only saves busy-work but also eliminates the possibility of accidentally shadowing test classes.<\/span>\n<ul>\n<li>The Django test runner has this since 1.6<\/li>\n<\/ul>\n<\/li>\n<li>Taking advantage of all the useful nose plugins\n<ul>\n<li>There are some cool plugins<\/li>\n<\/ul>\n<\/li>\n<li>Fixture bundling, an optional feature which speeds up your fixture-based tests by a factor of 4\n<ul>\n<li>Ok, Django doesn&#8217;t have this, but you shouldn&#8217;t be using fixtures anyways and there are other ways to make fixtures faster<\/li>\n<\/ul>\n<\/li>\n<li><span style=\"color: #808080;\">Reuse of previously created test DBs, cutting 10 seconds off startup time<\/span>\n<ul>\n<li>Django can do this since 1.8 https:\/\/docs.djangoproject.com\/en\/1.8\/releases\/1.8\/#tests<\/li>\n<\/ul>\n<\/li>\n<li><span style=\"color: #808080;\">Hygienic TransactionTestCases, which can save you a DB flush per test<\/span>\n<ul>\n<li>Django has had this since 1.6 https:\/\/docs.djangoproject.com\/en\/1.6\/topics\/testing\/tools\/#django.test.TransactionTestCase<\/li>\n<\/ul>\n<\/li>\n<li><span style=\"color: #808080;\">Support for various databases. Tested with MySQL, PostgreSQL, and SQLite. Others should work as well.<\/span>\n<ul>\n<li>Django has had this forever<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>So what if you need a certain nose plugin? Say, xunit for Jenkins or some other tooling? Well, you still have to use Nose because django-jux hasn&#8217;t been updated in 4 years.<\/p>\n<p>Here&#8217;s a small script you can use that lets you use Django + Nose while skipping the problematic Django-nose:<br \/>\n<script src=\"https:\/\/gist.github.com\/crccheck\/4efe2e28ffcba38aa242.js\"><\/script><\/p>\n<p>Run it like you would Nose:<\/p>\n<p><code>DJANGO_SETTING_MODULE=settings.test python runtests.py --with-xunit --with-cov<\/code><\/p>\n<p>One choice I made is that I use Django 1.8&#8217;s <code>--keepdb<\/code> flag instead of the <code>REUSE_DB<\/code> environment variable, but you can see how to adapt it if you wanted it to feel more like Nose. Adapting the command above to reuse the database would look like:<\/p>\n<p><code>DJANGO_SETTING_MODULE=settings.test python runtests.py --with-xunit --with-cov --keepdb<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve grown to dislike Django-Nose. It&#8217;s been over three months since Django 1.8 has been released and they still don&#8217;t have a release that fully supports it. These are the advantages they currently tout: Testing just your apps by default, not all the standard ones that happen to be in INSTALLED_APPS The Django test runner&hellip;<\/p>\n <a href=\"https:\/\/www.crccheck.com\/blog\/django-nose-without-django-nose\/\" title=\"Django Nose without Django-Nose\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">Django Nose without Django-Nose<\/span><\/a>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[4],"tags":[51,68],"class_list":["entry","author-showmewhatyougot","post-723","post","type-post","status-publish","format-standard","category-technical","tag-django","tag-testing"],"_links":{"self":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/comments?post=723"}],"version-history":[{"count":3,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/723\/revisions"}],"predecessor-version":[{"id":729,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/723\/revisions\/729"}],"wp:attachment":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/media?parent=723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/categories?post=723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/tags?post=723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}