3 ms·
Run the single test with "pytest tests/path/to/test_file.py::TestClass::test_method" instead of using pytest -k to parse all your test code looking for a method
by dmurray 4y ago
Run the single test with "pytest tests/path/to/test_file.py::TestClass::test_method" instead of using pytest -k to parse all your test code looking for a method with the right name.
Alternatively, your IDE or editor probably already has an extension that allows you to right click - run single test. VS Code at least has some plugin that collects the tests in the background.
- ssl232 4y agoTo add to this, the test ID pytest prints when a test has had a failure/warning is the same form you can call with pytest to run the test. For example, let's say pytest outputs this: =============================== warnings summary =============================== tests/parser/test_expressions.py::test_complex[+inf+1.23e7j-(inf+12300000j)] You can run just that particular test (with that particular parametrized input) with pytest tests/parser/test_expressions.py::test_complex[+inf+1.23e7j-(inf+12300000j)]
- BerislavLopac 4y agoTo add to that, pytest's parametrized IDs can be fully controlled in the test code [0], so your test can be something like: pytest tests/parser/test_expressions.py::test_complex[special_case_7] [0] https://docs.pytest.org/en/7.1.x/example/parametrize.html#different-options-for-test-ids https://docs.pytest.org/en/7.1.x/example/parametrize.html#di...
- masklinn 4y agoAlso pytest has flags like —lf and —sw to rerun failed tests or tackle test suites with lots of failures.
- cocoflunchy 4y agoThanks, it is a lot better (11s instead of 30)