Last active
August 29, 2015 14:23
-
-
Save hjwp/6e221dad25ea8c7430ff to your computer and use it in GitHub Desktop.
pytest print in finalizer attempts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import pytest | |
def pytest_runtest_call(item): | |
if hasattr(item, "_request"): | |
if hasattr(item._request, "_addoutput_on_failure"): | |
item._request._addoutput_on_failure() | |
@pytest.fixture | |
def print_on_fail(request): | |
def add(): | |
print ("test failed" + str(time.time())) | |
request._parent_request._addoutput_on_failure = add |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def test_doing_stuff(print_on_fail): | |
print('testing' + str(time.time())) | |
assert False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
============================= test session starts ============================= | |
platform linux -- Python 3.4.3 -- py-1.4.30 -- pytest-2.7.2 | |
rootdir: /tmp/t2, inifile: | |
collected 1 items | |
tests.py F | |
================================== FAILURES =================================== | |
______________________________ test_doing_stuff _______________________________ | |
print_on_fail = None | |
def test_doing_stuff(print_on_fail): | |
print('testing' + str(time.time())) | |
> assert False | |
E assert False | |
tests.py:5: AssertionError | |
---------------------------- Captured stdout call ----------------------------- | |
test failed1435573940.9372423 | |
testing1435573940.9373307 | |
========================== 1 failed in 0.01 seconds =========================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment