Skip to content

Test method collection does not follow documentation's naming convention. #8094

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

Closed
NikolasKomonen opened this issue Dec 2, 2020 · 5 comments
Labels
topic: collection related to the collection phase type: docs documentation improvement, missing or needing clarification

Comments

@NikolasKomonen
Copy link

pytest: 6.1.2
python: 3.6.8

The documentation indicates that naming must follow:

Test method names or function names should start with “test_”, as in test_example(). Methods with names that don’t match this pattern won’t be executed as tests.


But in my example:

# test_my_func.py

import pytest

def tester_my_function():
    assert False

def test_my_function():
    assert True 

if I call:

$ pytest --collect-only  

both functions get collected even though first ones name starts with tester_


If this the accepted functionality, I think that the documentation should be updated to indicate that it will collect it if it starts with test and not test_

@Zac-HD Zac-HD added topic: collection related to the collection phase type: docs documentation improvement, missing or needing clarification labels Dec 3, 2020
@aklajnert
Copy link
Contributor

The docs you've pointed out seems to be for some quite old version (2.9.2). In the current docs, this is stated correctly: https://docs.pytest.org/en/stable/goodpractices.html#conventions-for-python-test-discovery

I don't see any branch for the version of the docs you've linked to, I guess it is some leftover on readthedocs.

@NikolasKomonen
Copy link
Author

Thanks for figuring that out, @aklajnert


fyi when I search anything related to "pytest naming conventions" the outdated doc is the first result, if anyone plans to remove the page.

@nicoddemus
Copy link
Member

Yeah recently we had a few cases of misunderstandings because of old links.

Usually we only really keep two docs up-to-date, which is stable and latest.

What should we do with old documentation pages?

Btw the docs mentioned in the original issue are quite old, from the reorganize-docs branch, back in 2016. I don't think we will really pick it up again at this point, perhaps we can just delete them to avoid confusion? @pfctdayelise @hackebrot?

@nicoddemus
Copy link
Member

Closing this for now, #8098 is a follow up.

@nicoddemus
Copy link
Member

Thanks @aklajnert for figuring it out quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase type: docs documentation improvement, missing or needing clarification
Projects
None yet
Development

No branches or pull requests

4 participants