Pytest supports several ways to run and select tests from the command-line.
pytest test_mod.py
pytest testing/
pytest -k "MyClass and not method"
This will run tests which contain names that match the given string expression, which can include Python operators that use filenames, class names and function names as variables. The example above will run TestMyClass.test_something
but not TestMyClass.test_method_simple
.
Each collected test is assigned a unique nodeid
which consist of the module filename followed by specifiers like class names, function names and parameters from parametrization, separated by ::
characters.
pytest test_mod.py::test_func
Another example specifying a test method in the command line:
pytest test_mod.py::TestClass::test_method
pytest -m slow
Will run all tests which are decorated with the @pytest.mark.slow
decorator.
For more information see marks.
pytest --pyargs pkg.testing
This will import pkg.testing
and use its filesystem location to find and run tests from.
Source: https://docs.pytest.org/en/latest/usage.html#specifying-tests-selecting-tests