pytest-dev / pytest-dev/pytest

Errors in teardown_module erroneously attached to last executed test

Open
#657 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: reporting type: bug
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

UPDATE 2024-17-06: this bug is still alive and kicking

Originally reported by: David MacIver (BitBucket: david_maciver_, GitHub: david_maciver_)


Consider a test suite like the following:

#!python

def teardown_module(module):
    assert False


def test_stuff():
    pass


def test_things():
    pass

The result is:

collected 2 items 

test_module_teardown.py ..E

=================================================== ERRORS ===================================================
______________________________________ ERROR at teardown of test_things ______________________________________
Traceback (most recent call last):
  File "/home/david/projects/hypothesis/test_module_teardown.py", line 2, in teardown_module
    assert False
AssertionError: assert False


In particular the "ERROR at teardown of test_things" bit is weird. It's not a big deal, but it would be better if this didn't get attached to the test which just happens to have run last but was instead marked as belonging to the module.


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in test_module_teardown.py, focusing on teardown_module and the reported “ERROR at teardown of test_things” association. Trace how module teardown errors are attached to the final test, then verify that the failure is reported as belonging to the module rather than the last executed test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.