Simple test suite 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
Provide a test_suite argument to the setup call specifying the the setuptest.SetupTestSuite test suite, e.g.:
setup( # ... test_suite='setuptest.SetupTestSuite', )
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 test_settings module in the same path as your app’s setup.py. These settings will be used when executing the tests, e.g. in test_settings.py:
DATABASE_ENGINE = 'sqlite3' INSTALLED_APPS = ( 'myapp', )
In order for the test suite to find your tests you must provide either a packages or py_modules argument to the setup call, e.g.:
from setuptools import setup, find_packages setup( # ... packages=find_packages(), ) # Or alternatively... setup( # ... py_modules=['myapp'], )
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.
To mute the output of the 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/__init__.py:6:1: W391 blank line at end of file $
Changelog
0.0.6 (2011-09-08)
Refactor, cleanup, self contained suite class.
0.0.5 (2011-09-06)
Added frame hack to resolve packages and py_modules to test, no longer needs app specific test suite.
0.0.4 (2011-09-06)
Refactored the app to use a callback style approach instead of monkey patching. Thanks jezdez.
0.0.3 (2011-08-30)
More robust test settings import.
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.6-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ee5f459ff274ba5b7682b707748c647d0d8cd77fd7f26d76cca86bc63617b3e |
|
MD5 | 9e7e790ce4b2052aa6c881da332e8328 |
|
BLAKE2b-256 | 946fe29a9044058f35a44b3efee5d27351f233c656784b2236845c6b8b23c6fa |
Hashes for django_setuptest-0.0.6-py2.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64d78402f245a8dba5b9ed235334ed69083c347a5af4a0ba52574b9b7a0bd0a5 |
|
MD5 | d2c5dd1f58c2623b1ab99d93a4f6ce44 |
|
BLAKE2b-256 | 43e5210db98df0de6b9355f5fbbfa32b2b1044c17237ef2e9e1c87170f0b4e11 |