question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confusing log for teardown

See original GitHub issue

Description

For test files where the last test is skipped, if module level teardown incurs exception, the exception would still be attributed to the skipped test.

Example

  1. Save the following snippet as test.py
import pytest

def teardown_module():
    print('executed teardown')
    raise RuntimeError()

def test_test():
    print('executed test')
    pass

@pytest.mark.skip(reason='something')
def test_skipped():
    print('executed skipped')
    pass
  1. run pytest -v test.py

  2. output

% pytest -v test.py
==================================================================== test session starts =====================================================================
platform darwin -- Python 3.7.7, pytest-5.4.1, py-1.8.0, pluggy-0.13.1 -- /usr/local/opt/python/bin/python3.7
cachedir: xx
rootdir: xx
plugins: env-0.6.2, xdist-1.31.0, forked-1.1.3, cov-2.8.1
collected 2 items

test.py::test_test PASSED                                                                                                                         [ 50%]
test.py::test_skipped SKIPPED                                                                                                                     [100%]
test.py::test_skipped ERROR                                                                                                                       [100%]

=========================================================================== ERRORS ===========================================================================
_____________________________________________________________ ERROR at teardown of test_skipped ______________________________________________________________

    def teardown_module():
        print('executed teardown')
>       raise RuntimeError()
E       RuntimeError

test.py:5: RuntimeError
------------------------------------------------------------------ Captured stdout teardown ------------------------------------------------------------------
executed teardown
================================================================== short test summary info ===================================================================
ERROR test.py::test_skipped - RuntimeError
=========================================================== 1 passed, 1 skipped, 1 error in 0.21s ============================================================

Env

OSX w/ pytest 5.4.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Zac-HDcommented, Jun 9, 2020

I think this is working as intended - while it might be unintuitive, changing where we report teardown errors depending on skipped status (which can be decided within the test, and potentially nondeterministically!) is likely to cause worse problems.

0reactions
RonnyPfannschmidtcommented, Jun 9, 2020

setting this as duplicate of #895

Read more comments on GitHub >

github_iconTop Results From Across the Web

Robotframework: behavior when teardown fails - Stack Overflow
Sometimes the test fails in tear down is an important issue, for example, the clean up is not completed and it causes other...
Read more >
I think I can play Teardown after this... - YouTube
It turns out the treadmill never left Teardown...Leave a like and Subscribe if you enjoyed! Thanks =)Subscribe!
Read more >
UnitySetUp and UnityTearDown | Test Framework | 1.1.33
Log ("This runs inside playmode"); } [UnityTearDown] public IEnumerator TearDown() { yield return new ExitPlayMode(); } } ...
Read more >
Teardown: Recon Sentinel - Hackaday
The LCD showed an error message about connectivity, but I was able to log in over SSH with no issue at that point....
Read more >
UnitySetUp and UnityTearDown | Test ... - Unity - Manual
Log ("This runs inside playmode"); } [UnityTearDown] public IEnumerator TearDown() { yield return new ExitPlayMode(); } } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found