S
S
Sergey2020-08-26 17:51:12
Python
Sergey, 2020-08-26 17:51:12

How to run tests in Pytest from a list?

Good day!
Essence of the question: here I worked out a job in Jenkins, generated a report with fallen tests (~ 100 pieces of the form: test_01.TestClass_01.test_01[001])

Is it possible to somehow make a list of such tests and run them? Just labeling 100 tests manually and then running Pytest with the -m or -k switch is a lot of work...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2020-08-26
@x__miller_x

Well, the simplest thing is to create a text file (tests.txt) with a list of tests (one test on each line) like

tests.py::TestClass::testMethod
tests.py::TestClass::testMethod2
tests.py::TestClass::testMethod3

And then execute in the console:
cat tests.txt|xargs pytest
You will start running these tests one by one

V
Vlad Grigoriev, 2020-08-26
@Vaindante

somehow you collect the list of failed tests, at least parse the report from the run.
You can use the pytest_terminal_summary hook and go through the failed tests in it and upload them somewhere, you can use any other hook in general, it’s not so important.
You take the pytest_collection_modifyitems hook and in it you filter the list to run, excluding all tests that are not in the list of failed tests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question