Задать вопрос

Тел: +7 965 3737 888

529

Просмотров

0

Ответов

Deep package test runner

<p><strong>NOTE: This is modified from 1.0's test runner and has only been tested on Django 1.0 + Python 2.5</strong>
</p>
<p>This is a test runner that searches inside any app-level "tests" packages for django unit tests.  Modules to be searched must have names that start with "test_" (this can be changed by modifying get_multi_tests(), [mod.startswith('test_') and mod.endswith('.py')]).
</p>
<p>It also allows for arbitrarily nested test packages, with no restrictions on naming, so you could have:
</p>
myapp/
+- tests/
    +- __init__.py
    +- test_set1.py
    +- category1/
        +- __init__.py
        +- test_something.py
        +- subcat/
            +- __init__.py
            +- test_foobar.py
    +- category2/
        +- __init__.py
        +- test_other.py
<p>and "manage.py test myapp" would pick up tests in all four test_*.py test modules.
</p>
<p>Searching the modules in this way, instead of importing them all into the top-level __init__.py, allows you to have "name collisions" with TestCase names -- two modules can each have a TestFooBar class, and they will both be run.  Unfortunately, this snippet doesn't allow you to specify a full path to a specific test case or test module ("manage.py test myapp.category1.test_something" and "manage.py test myapp.test_set1.TestFooBar" won't work); using "manage.py test myapp.TestFooBar" will search out all test cases named "TestFooBar" and run them.  "manage.py test myapp.TestFooBar.test_baz" will work similarly, returning the test_baz method of each TestFooBar class.
</p>
<p>To use, put this code in "testrunner.py" in your project, and add TEST_RUNNER = 'myproject.testrunner.run_tests' to your settings.py.
</p>

Вопрос полезен? Да0/Нет0
file_5129.py(8.2Кб)
None