module documentation

Undocumented

Class Approximate Undocumented
Class CaptureQueriesContext Context manager that captures queries executed by the specified connection.
Class ContextList A wrapper that provides direct key access to context items contained in a list of context objects.
Class ignore_warnings Undocumented
Class isolate_apps Act as either a decorator or a context manager to register models defined in its wrapped context to an isolated registry.
Class LoggingCaptureMixin Capture the output from the 'django' logger and store it on the class's logger_output attribute.
Class modify_settings Like override_settings, but makes it possible to append, prepend, or remove items instead of redefining the entire list.
Class NullTimeKeeper Undocumented
Class override_script_prefix Decorator or context manager to temporary override the script prefix.
Class override_settings Act as either a decorator or a context manager. If it's a decorator, take a function and return a wrapped function. If it's a contextmanager, use it with the ``with`` statement. In either event, entering/exiting are called before and after, respectively, the function/block is executed.
Class override_system_checks Act as a decorator. Override list of registered system checks. Useful when you override `INSTALLED_APPS`, e.g. if you exclude `auth` app, you also need to exclude its system checks.
Class TestContextDecorator A base class that can either be used as a context manager during tests or as a test function or unittest.TestCase subclass decorator to perform temporary alterations.
Class TimeKeeper Undocumented
Function captured_output Return a context manager used by captured_stdout/stdin/stderr that temporarily replaces the sys stream *stream_name* with a StringIO.
Function captured_stderr Capture the output of sys.stderr:
Function captured_stdin Capture the input to sys.stdin:
Function captured_stdout Capture the output of sys.stdout:
Function compare_xml Try to do a 'xml-comparison' of want and got. Plain string comparison doesn't always work because, for example, attribute ordering should not be important. Ignore comment nodes, processing instructions, document type node, and leading and trailing whitespaces.
Function dependency_ordered Reorder test_databases into an order that honors the dependencies described in TEST[DEPENDENCIES].
Function extend_sys_path Context manager to temporarily add paths to sys.path.
Function freeze_time Context manager to temporarily freeze time.time(). This temporarily modifies the time function of the time module. Modules which import the time function directly (e.g. `from time import time`) won't be affected This isn't meant as a public API, but helps reduce some repetitive code in Django's test suite.
Function get_runner Undocumented
Function get_unique_databases_and_mirrors Figure out which databases actually need to be created.
Function instrumented_test_render An instrumented Template render method, providing a signal that can be intercepted by the test Client.
Function isolate_lru_cache Clear the cache of an LRU cache object on entering and exiting.
Function iter_test_cases Return an iterator over a test suite's unittest.TestCase objects.
Function register_lookup Context manager to temporarily register lookups on a model field using lookup_name (or the lookup's lookup_name if not provided).
Function require_jinja2 Decorator to enable a Jinja2 template engine in addition to the regular Django template engine for a test or skip it if Jinja2 isn't available.
Function setup_databases Create the test databases.
Function setup_test_environment Perform global pre-test setup, such as installing the instrumented template renderer and setting the email backend to the locmem email backend.
Function tag Decorator to add tags to a test class or method.
Function teardown_databases Destroy all the non-mirror databases.
Function teardown_test_environment Perform any global post-test teardown, such as restoring the original template renderer and restoring the email sending functions.
Constant TZ_SUPPORT Undocumented
Variable requires_tz_support Undocumented
Class _TestState Undocumented
@contextmanager
def captured_output(stream_name): (source)

Return a context manager used by captured_stdout/stdin/stderr that temporarily replaces the sys stream *stream_name* with a StringIO. Note: This function and the following ``captured_std*`` are copied from CPython's ``test.support`` module.

def captured_stderr(): (source)

Capture the output of sys.stderr: with captured_stderr() as stderr: print("hello", file=sys.stderr) self.assertEqual(stderr.getvalue(), "hello ")

def captured_stdin(): (source)

Capture the input to sys.stdin: with captured_stdin() as stdin: stdin.write('hello ') stdin.seek(0) # call test code that consumes from sys.stdin captured = input() self.assertEqual(captured, "hello")

def captured_stdout(): (source)

Capture the output of sys.stdout: with captured_stdout() as stdout: print("hello") self.assertEqual(stdout.getvalue(), "hello ")

def compare_xml(want, got): (source)

Try to do a 'xml-comparison' of want and got. Plain string comparison doesn't always work because, for example, attribute ordering should not be important. Ignore comment nodes, processing instructions, document type node, and leading and trailing whitespaces. Based on https://github.com/lxml/lxml/blob/master/src/lxml/doctestcompare.py

def dependency_ordered(test_databases, dependencies): (source)

Reorder test_databases into an order that honors the dependencies described in TEST[DEPENDENCIES].

@contextmanager
def extend_sys_path(*paths): (source)

Context manager to temporarily add paths to sys.path.

@contextmanager
def freeze_time(t): (source)

Context manager to temporarily freeze time.time(). This temporarily modifies the time function of the time module. Modules which import the time function directly (e.g. `from time import time`) won't be affected This isn't meant as a public API, but helps reduce some repetitive code in Django's test suite.

def get_runner(settings, test_runner_class=None): (source)

Undocumented

def get_unique_databases_and_mirrors(aliases=None): (source)

Figure out which databases actually need to be created. Deduplicate entries in DATABASES that correspond the same database or are configured as test mirrors. Return two values: - test_databases: ordered mapping of signatures to (name, list of aliases) where all aliases share the same underlying database. - mirrored_aliases: mapping of mirror aliases to original aliases.

def instrumented_test_render(self, context): (source)

An instrumented Template render method, providing a signal that can be intercepted by the test Client.

@contextmanager
def isolate_lru_cache(lru_cache_object): (source)

Clear the cache of an LRU cache object on entering and exiting.

def iter_test_cases(tests): (source)

Return an iterator over a test suite's unittest.TestCase objects. The tests argument can also be an iterable of TestCase objects.

@contextmanager
def register_lookup(field, *lookups, lookup_name=None): (source)

Context manager to temporarily register lookups on a model field using lookup_name (or the lookup's lookup_name if not provided).

def require_jinja2(test_func): (source)

Decorator to enable a Jinja2 template engine in addition to the regular Django template engine for a test or skip it if Jinja2 isn't available.

def setup_databases(verbosity, interactive, *, time_keeper=None, keepdb=False, debug_sql=False, parallel=0, aliases=None, serialized_aliases=None, **kwargs): (source)

Create the test databases.

def setup_test_environment(debug=None): (source)

Perform global pre-test setup, such as installing the instrumented template renderer and setting the email backend to the locmem email backend.

def tag(*tags): (source)

Decorator to add tags to a test class or method.

def teardown_databases(old_config, verbosity, parallel=0, keepdb=False): (source)

Destroy all the non-mirror databases.

def teardown_test_environment(): (source)

Perform any global post-test teardown, such as restoring the original template renderer and restoring the email sending functions.

TZ_SUPPORT = (source)

Undocumented

Value
hasattr(time, 'tzset')
requires_tz_support = (source)

Undocumented