Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

py.test logging for tests that pass

Tags:

python

pytest

I have been over and over the documentation, but I can not fine out how I get py.test to write to the log for tests that pass. For example if I run "py.test --resultlog=mylog.txt myPytest.py" mylog.txt only has one line for each test that passed. I want to add other things to each test recorded in my log file, regardless whether thy passed or failed. For example I need to know the time they ran, some of the output data etc. How do I get py.test to include data about the test (passed and failed) in the py.test log file?

like image 345
user3750195 Avatar asked Jan 09 '15 03:01

user3750195


2 Answers

pytest now supports the -s argument to prevent capturing logging calls for passing tests.

pytest -s

From the documentation:

-s, –capture=no Normally stdout and stderr are captured and only shown for failing tests. The -s option can be used to disable capturing, showing stdcalls for print statements, logging calls, etc.

like image 75
Dylan Hogg Avatar answered Nov 01 '22 00:11

Dylan Hogg


You can have a look if the junitxml output provides any more information. But I suspect that if you want the actual time rather then duration etc you will have to write your own plugin. The documentation gives you the relevant hooks: http://pytest.org/latest/plugins.html?highlight=hooks#reporting-hooks

like image 1
flub Avatar answered Oct 31 '22 23:10

flub