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

Rule to disallow assertions in fixtures #31

Open
m-burst opened this issue May 7, 2020 · 3 comments
Open

Rule to disallow assertions in fixtures #31

m-burst opened this issue May 7, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@m-burst
Copy link
Owner

m-burst commented May 7, 2020

Rule request

Description

The rule should check that there are no assert statements in fixtures.

Rationale

@m-burst m-burst added the enhancement New feature or request label May 7, 2020
@sobolevn
Copy link

sobolevn commented May 7, 2020

I don't agree on this one. Many people use fixtures for custom complex asserts. I can even say that this is the best practice.

Examples:

@m-burst
Copy link
Owner Author

m-burst commented May 7, 2020

@sobolevn These cases are not what I meant. If the fixture function returns a function which has some assertions in it, that is fine, since the function is called during test code execution and thus becomes part of the test code.

What I see as a violation is making assertions in the fixture function itself, i.e. during setup/teardown:

@pytest.fixture()
def my_thing():
    thing = get_my_thing()
    assert thing.some_attribute
    return thing

In the above case, if the assertion on thing needs to be made, it should be a separate test case.

@sobolevn
Copy link

sobolevn commented May 7, 2020

Yes, this seems legit! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants