Simple module enabling Django app testing via $ python setup.py test
Project description
Django Setuptest
Simple module enabling Django app testing via $ python setup.py test.
Normally when you execute $ python setup.py test for Django related modules you’re almost certain to run into DJANGO_SETTINGS_MODULE environment variable issues, e.g.:
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
This module overcomes this by configuring the DJANGO_SETTINGS_MODULE environment variable before executing your test suite. As a bonus it also generates Coverage and PEP 8 reports as part of the test.
Installation
Add the following to the package’s setup.py file before the setup call:
from setuptools.command.test import test def run_tests(self): from setuptest.runtests import runtests return runtests(self) test.run_tests = run_tests setup( # ... )
Provide a test_suite argument to the setup call specifying the test suite, e.g.:
setup( # ... test_suite = "my_django_package.tests" )
Provide a tests_require argument to the setup call including django-setuptest (required) and other package dependencies needed to execute the tests, e.g.:
setup( # ... tests_require=[ 'django-setuptest', ], )
Specify the test specific Django settings in a settings module within the test suite. These setting will be used when executing the tests, e.g. in my_django_package/tests/settings.py:
DATABASE_ENGINE = 'sqlite3' INSTALLED_APPS = [ 'my_django_package', ]
Usage
Once correctly configured you can execute tests from the command line:
$ python setup.py test
This should output your test results as well as Coverage and PEP 8 reports. Note that an XML Coverage report is generated in a file called coverage.xml and a PEP8 report is generated in a file called pep8.txt
To mute the output of Coverage and PEP 8 reports provide the --quiet option:
$ python setup.py test --quiet
Sample Output
Example output of dummy test including Coverage and PEP 8 reports:
$ python setup.py test running test running egg_info writing django_dummy.egg-info/PKG-INFO writing top-level names to django_dummy.egg-info/top_level.txt writing dependency_links to django_dummy.egg-info/dependency_links.txt reading manifest file 'django_dummy.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'django_dummy.egg-info/SOURCES.txt' running build_ext Creating test database for alias 'default'... E ====================================================================== ERROR: test_something (dummy.tests.TestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/shaun/tmp/django-dummy/dummy/tests/__init__.py", line 6, in test_something raise NotImplementedError('Test not implemented. Bad developer!') NotImplementedError: Test not implemented. Bad developer! ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (errors=1) Destroying test database for alias 'default'... Coverage Report: Name Stmts Miss Cover Missing ----------------------------------------------- dummy/models 20 2 90% 22, 55 PEP8 Report: dummy/tests/settings.py:6:1: W391 blank line at end of file $
Changelog
0.0.2 (2011-08-29)
Repeat Pep 8 errors.
0.0.1 (2011-08-29)
Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for django_setuptest-0.0.2-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9830cd666993d5cb6a7d06a1e0936b72c2693cfacd4a6a301cd4a7cc45bf15f8 |
|
MD5 | a24edff6aa59aa5b9bb9bebf7ed0a51a |
|
BLAKE2b-256 | eef19e3416db05047d5b23660d315f2d47f3893b53ffdc74655e2066da296e33 |
Hashes for django_setuptest-0.0.2-py2.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e054e7f13fa65a2d1b526d41b7163790a7c34175e4e2f70bb5d0d9967313c86 |
|
MD5 | 7b09e895dc14937228d40d7d4b48ca13 |
|
BLAKE2b-256 | 3da3c6d36bcd36d747d4ae0f8f1108cc4271b6ffe6d32b015e6eebc01e0d7165 |