python - For a django unit test, why do some test runners take into account the production database, and others do not? -
as part of bringing django tutorial app, noticed test runners going out production database when running unit tests, while other test runners appeared ignore it.
i pared down django app basic features, 3 tests:
- model instantiation (a control test)
- request on empty database
- request on database 1 element
i added single element production database, , ran them through test runners eclipse pydev uses.
code available on my github site.
the django test runner passes (claims creating test database?):
(django)kenners@elendil:~/my_first_app$ python manage.py test demo creating test database alias 'default'... ... ---------------------------------------------------------------------- ran 3 tests in 0.135s ok destroying test database alias 'default'...
the pytest runner passes (without such claim, though might hidden):
(django)kenners@elendil:~/my_first_app$ python -m pytest demo/tests.py =============================================================================== test session starts ================================================================================ platform linux2 -- python 2.7.3 -- pytest-2.4.2 plugins: django collected 3 items demo/tests.py ... ============================================================================= 3 passed in 1.29 seconds =============================================================================
the nose runner fails (it's combining production database tests):
(django)kenners@elendil:~/my_first_app$ python -m nose demo/tests.py ff. ====================================================================== fail: test_no_available_things (demo.tests.demodatabasetests) ---------------------------------------------------------------------- traceback (most recent call last): file "/home/kenners/my_first_app/demo/tests.py", line 23, in test_no_available_things self.assertequals(0, pull_count_from_body(response)) assertionerror: 0 != 1 ====================================================================== fail: test_one_available_things (demo.tests.demodatabasetests) ---------------------------------------------------------------------- traceback (most recent call last): file "/home/kenners/my_first_app/demo/tests.py", line 30, in test_one_available_things self.assertequals(1, pull_count_from_body(response)) assertionerror: 1 != 2 ---------------------------------------------------------------------- ran 3 tests in 0.334s failed (failures=2)
the unittest2 runner fails (for same reason):
(django)kenners@elendil:~/my_first_app$ python -m unittest2 demo.tests ff. ====================================================================== fail: test_no_available_things (demo.tests.demodatabasetests) ---------------------------------------------------------------------- traceback (most recent call last): file "demo/tests.py", line 23, in test_no_available_things self.assertequals(0, pull_count_from_body(response)) assertionerror: 0 != 1 ====================================================================== fail: test_one_available_things (demo.tests.demodatabasetests) ---------------------------------------------------------------------- traceback (most recent call last): file "demo/tests.py", line 30, in test_one_available_things self.assertequals(1, pull_count_from_body(response)) assertionerror: 1 != 2 ---------------------------------------------------------------------- ran 3 tests in 0.348s failed (failures=2)
what part of nose / unittest2 causes these tests fail? why pytest working?
touching production database while running unit-tests absolutely inappropriate. unit tests should work on mock database. integration tests should work on real, test database. production database? why want risk real data?
django documentation claims "the test runner takes care of creating own test database".
in django-nose documentation can seen supposed run tests on test database.
Comments
Post a Comment