Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are there hooks for module setup/teardown? #3677

Closed
yoyoyopcp opened this issue Jul 10, 2018 · 5 comments
Closed

Are there hooks for module setup/teardown? #3677

yoyoyopcp opened this issue Jul 10, 2018 · 5 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@yoyoyopcp
Copy link

There are many hooks around setting up/tearing down functions and there are hooks for session start/finish, but are there any for modules?

@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #265 (teardown method called even for skipped tests (and setup isn't)), #2205 (optimize io capture setup/teardown), #91 (Package-level setup and teardown), #2718 (Please consider adding context manager versions of setup/teardown), and #377 (nose's .setUp() and .tearDown() are not supported).

@pytestbot pytestbot added platform: mac mac platform-specific problem type: enhancement new feature or API change, should be merged into features branch labels Jul 10, 2018
@nicoddemus nicoddemus added type: question general question, might be closed after 2 weeks of inactivity and removed platform: mac mac platform-specific problem type: enhancement new feature or API change, should be merged into features branch labels Jul 10, 2018
@nicoddemus
Copy link
Member

Hi @yoyoyopcp,

The short answer is no, the closest I can think of are the pytest_fixture_setup and pytest_fixture_post_finalizer hooks when they are used for module-scoped fixtures.

@asottile
Copy link
Member

This might be helpful:

import pytest

@pytest.fixture(autouse=True, scope='module')
def module_setup_teardown():
    print("MODULE SETUP!!!")
    yield
    print("MODULE TEARDOWN!!!")


def test1():
    print("TEST1!!!")


def test2():
    print("TEST2!!!")
$ pytest -s test.py
============================== test session starts ===============================
platform darwin -- Python 3.7.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: /private/tmp/t, inifile:
collected 2 items                                                                

test.py MODULE SETUP!!!
TEST1!!!
.TEST2!!!
.MODULE TEARDOWN!!!


============================ 2 passed in 0.01 seconds ============================

@asottile
Copy link
Member

oh but for plugin hooks, 🤔

@Zac-HD Zac-HD closed this as completed Oct 21, 2018
@RonnyPfannschmidt
Copy link
Member

Plugins can just make a internal fixtures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

6 participants