@@ -52,23 +52,64 @@ To stop the testing process after the first (N) failures::
52
52
Specifying tests / selecting tests
53
53
---------------------------------------------------
54
54
55
- Several test run options::
56
-
57
- pytest test_mod.py # run tests in module
58
- pytest somepath # run all tests below somepath
59
- pytest -k stringexpr # only run tests with names that match the
60
- # "string expression", e.g. "MyClass and not method"
61
- # will select TestMyClass.test_something
62
- # but not TestMyClass.test_method_simple
63
- pytest test_mod.py::test_func # only run tests that match the "node ID",
64
- # e.g. "test_mod.py::test_func" will select
65
- # only test_func in test_mod.py
66
- pytest test_mod.py::TestClass::test_method # run a single method in
67
- # a single class
68
-
69
- Import 'pkg' and use its filesystem location to find and run tests::
70
-
71
- pytest --pyargs pkg # run all tests found below directory of pkg
55
+ Pytest supports several ways to run and select tests from the command-line.
56
+
57
+ **Run tests in a module **
58
+
59
+ ::
60
+
61
+ pytest test_mod.py
62
+
63
+ **Run tests in a directory **
64
+
65
+ ::
66
+
67
+ pytest testing/
68
+
69
+ **Run tests by keyword expressions **
70
+
71
+ ::
72
+
73
+ pytest -k "MyClass and not method"
74
+
75
+ This will run tests which contain names that match the given *string expression *, which can
76
+ include Python operators that use filenames, class names and function names as variables.
77
+ The example above will run ``TestMyClass.test_something `` but not ``TestMyClass.test_method_simple ``.
78
+
79
+ .. _nodeids :
80
+
81
+ **Run tests by node ids **
82
+
83
+ Each collected test is assigned a unique ``nodeid `` which consist of the module filename followed
84
+ by specifiers like class names, function names and parameters from parametrization, separated by ``:: `` characters.
85
+
86
+ To run a specific test within a module::
87
+
88
+ pytest test_mod.py::test_func
89
+
90
+
91
+ Another example specifying a test method in the command line::
92
+
93
+ pytest test_mod.py::TestClass::test_method
94
+
95
+ **Run tests by marker expressions **
96
+
97
+ ::
98
+
99
+ pytest -m slow
100
+
101
+ Will run all tests which are decorated with the ``@pytest.mark.slow `` decorator.
102
+
103
+ For more information see :ref: `marks <mark >`.
104
+
105
+ **Run tests from packages **
106
+
107
+ ::
108
+
109
+ pytest --pyargs pkg.testing
110
+
111
+ This will import ``pkg.testing `` and use its filesystem location to find and run tests from.
112
+
72
113
73
114
Modifying Python traceback printing
74
115
----------------------------------------------
0 commit comments