Skip to content

functions starting with test_ in non-test modules are incorrectly collected as tests when imported from a test_ module #11494

@DetachHead

Description

@DetachHead
  • a detailed description of the bug or problem you are having
    when importing a function where its name starts with test_ from a module that would normally be ignored by pytest, it gets incorrectly recognized as a test.

  • output of pip list from the virtual environment you are using

    Package Version ---------- ------- pip 22.3.1 setuptools 65.5.0 
  • pytest and operating system versions
    pytest 7.4.2, windows 10

  • minimal example if possible

    # some_module/utils.py def test_not_a_test(): """this function is incorrectly detected as a test when imported from test_foo.py""" # test_foo.py from some_module.utils import test_not_a_test def test_foo(): test_not_a_test()

when collecting, pytest should check the module of each function to make sure it's defined in the same file to prevent it from incorrectly matching imported functions from different modules

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: collectionrelated to the collection phasetype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions