Reference

@pytest.mark.dependency(name=None, depends=[], scope='module')

Mark a test to be used as a dependency for other tests or to depend on other tests.

This will cause the test results to be registered internally and thus other tests may depend on the test. The list of dependencies for the test may be set in the depends argument.

Parameters:
  • name (str) – the name of the test to be used for referencing by dependent tests. If not set, it defaults to the node ID defined by pytest. The name must be unique.
  • depends (iterable of str) – dependencies, a list of names of tests that this test depends on. The test will be skipped unless all of the dependencies have been run successfully. The dependencies must also have been decorated by the marker. The names of the dependencies must be adapted to the scope.
  • scope (str) – the scope to search for the dependencies. Must be either ‘session’, ‘package’, ‘module’, or ‘class’.

See Section Names for details on the default name if the name argument is not set and on how references in the depends argument must be adapted to the scope.

Changed in version 0.5.0: the scope parameter has been added.

pytest_dependency.depends(request, other, scope='module')

Add dependency on other test.

Call pytest.skip() unless a successful outcome of all of the tests in other has been registered previously. This has the same effect as the depends keyword argument to the pytest.mark.dependency() marker. In contrast to the marker, this function may be called at runtime during a test.

Parameters:
  • request – the value of the request pytest fixture related to the current test.
  • other (iterable of str) – dependencies, a list of names of tests that this test depends on. The names of the dependencies must be adapted to the scope.
  • scope (str) – the scope to search for the dependencies. Must be either ‘session’, ‘package’, ‘module’, or ‘class’.

New in version 0.2.

Changed in version 0.5.0: the scope parameter has been added.