Skip to content

setUpModule/tearDownModule not invoked #12219

Closed
@jaraco

Description

@jaraco

In #4064, on pytest 2.x, it was determined that unittest supported the unittest setUpModule and tearDownModule.

However, with pytest 8.x, I'm finding that it's not supported, even though the docs say it is.

In particular, I'm porting CPython's test_tarfile to backports.tarfile. When I run the tests, the setUpModule is never called.

Interestingly, the hook does seem to be honored in a minimized example.

 draft @ cat test_.py
def setUpModule():
    print(setUpModule.__name__)

def tearDownModule():
    print(tearDownModule.__name__)

def test():
    print(test.__name__)

def test2():
    print(test2.__name__)
 draft @ pip-run pytest -- -m pytest -s
============================================================== test session starts ===============================================================
platform darwin -- Python 3.12.2, pytest-8.1.1, pluggy-1.4.0
rootdir: /Users/jaraco/draft
collected 2 items                                                                                                                                

test_.py setUpModule
test
.test2
.tearDownModule


=============================================================== 2 passed in 0.00s ================================================================

If on the other hand, I add the following to conftest.py, the setup/teardown methods are called:

@pytest.fixture(scope='module', autouse=True)
def setup_and_teardown_module(request):
    request.module.setUpModule()
    try:
        yield
    finally:
        request.module.tearDownModule()

But it seems like that should be unnecessary if unittest's setUpMethod and tearDownMethod are supported.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions