Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display the test name *after* the test using pytest?

Tags:

python

pytest

Most of the time when I'm using pytest, the output is very, very long. More than a hundred lines. And often times I want this output, I really do. --tb=short isn't really a very good approach. But I don't want to have to scroll back 200 lines in my tmux window to find my test output because that's also super annoying.

What I would love to have is something like this:

______________________ >>test_my_test_with_a_lot_of_output _______________________
# imagine lots of test output here
______________________ <<test_my_test_with_a_lot_of_output _______________________

Is there some flag or setting I can use in py.test to achieve this kind of output?

like image 806
Wayne Werner Avatar asked Jun 05 '17 20:06

Wayne Werner


People also ask

How pytest identifies the test files and test methods?

Pytest automatically identifies those files as test files. We can make pytest run other filenames by explicitly mentioning them. Pytest requires the test function names to start with test. Function names which are not of format test* are not considered as test functions by pytest.

How do I test a specific test pytest?

Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m .

How do I get a pytest report?

To generate HTML reports with the Pytest framework we have to install a plugin. For the installation, we shall execute the command pip install pytest-html. Next to generate the report we shall run the command pytest –html=report. html.

Which command can be used to show all available fixtures?

Additionally, if you wish to display a list of fixtures for each test, try the --fixtures-per-test flag.


1 Answers

Use "pytest -rA" when running tests

see docs here

like image 65
Aaron Melgar Avatar answered Nov 16 '22 20:11

Aaron Melgar