djblets.testing.testrunners¶
- class TestRunner(nose_options: Optional[List[str]] = None, test_packages: Optional[List[str]] = None, needs_collect_static: Optional[bool] = None, use_pytest: bool = False, pytest_options: Optional[List[str]] = None, *args, **kwargs)[source]¶
Bases:
DiscoverRunner
Test runner for standard Djblets-based projects.
This class provides all the common setup for settings, databases, and directories that are generally needed by Django projects using Djblets. Much of the behavior can be overridden by subclasses.
nose is used to run the test suites. The options can be configured through
nose_options
.This can be subclassed in order to set the settings for the test run, or it can be instantiated with those settings passed in as keyword arguments.
- __init__(nose_options: Optional[List[str]] = None, test_packages: Optional[List[str]] = None, needs_collect_static: Optional[bool] = None, use_pytest: bool = False, pytest_options: Optional[List[str]] = None, *args, **kwargs) None [source]¶
Initialize the test runner.
The caller can override any of the options otherwise defined on the class.
Changed in version 4.0: Added the
use_pytest
andpytest_options
arguments.- Parameters:
nose_options (
list
, optional) – A list of options used for nose. Seenose_options
.test_packages (
list
, optional) – A list of Python package/module names to test. Seetest_packages
.needs_collect_static (
bool
, optional) – Whether or notcollectstatic
needs to be run before tests. Seeneeds_collect_static
.use_pytest (
bool
, optional) –Whether to run the tests using Pytest instead of Nose. This will become the default in Djblets 5.0.
New in version 4.0.
pytest_options (
list
, optional) –A list of options used for pytest. See
pytest_options
.New in version 4.0.
- nose_options = ['-v', '--match=^test', '--with-id', '--with-doctest', '--doctest-extension=.txt'][source]¶
The options used for nose.
This is a list of command line arguments that would be passed to nosetests.
- pytest_options: List[str] = []¶
The options used for pytest.
This is a list of command line arguments that would be passed to pytest.
New in version 4.0.
- setup_test_environment(*args, **kwargs)[source]¶
Set up an environment for the unit tests.
This will handle setting all the default settings for a Djblets-based project and will create the directory structure needed for the tests in a temp directory.
Subclasses can override this to provide additional setup logic.
This must be called before
run_tests()
.
- teardown_test_environment(*args, **kwargs)[source]¶
Tear down the environment for the unit tests.
This will clean up the temp directory structure.It must be called after
run_tests()
.
- __annotations__ = {'pytest_options': typing.List[str], 'test_packages': typing.List[str], 'use_pytest': <class 'bool'>}¶
- run_tests(test_labels=[], argv=None, *args, **kwargs)[source]¶
Run the test suite.
- Parameters:
- Returns:
The exit code. 0 means all tests passed, while 1 means there were failures.
- Return type:
- setup_dirs()[source]¶
Set up directories to create and use.
This can return one or more directory paths that need to be created before the tests can be run. It may also store settings pointing to those paths.
This is not responsible for creating the directories. Any returned paths will be created automatically.