pytest-dev / pytest-dev/pytest

Test collection fails with repeated test module name (but unique paths)

Open
#9,301 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: collection
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

While working on https://github.com/conda-forge/staged-recipes/pull/16888 (and after fixing the issues in #9300), I'm still having collection problems:

==================================== ERRORS ====================================
________ ERROR collecting tensorflow_addons/layers/tests/snake_test.py _________
import file mismatch:
imported module 'snake_test' has this __file__ attribute:
  $SRC_DIR/tensorflow_addons/activations/tests/snake_test.py
which is not the same as the test file we want to collect:
  $SRC_DIR/tensorflow_addons/layers/tests/snake_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

This is because upstream has both
tensorflow_addons/activations/tests/snake_test.py as well as tensorflow_addons/layers/tests/snake_test.py.

While I can see that reusing the name for the file is not ideal, it's something that can happen fairly easily in larger code bases, and since the path is unique (i.e. distinguished by the containing folder), I don't really see why this shouldn't be working / supported?

If the answer is no, I'll can work around it (e.g. carrying a patch that renames the tests), but wanted to ask at least.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce collection with the two named snake_test.py paths under tensorflow_addons/activations/tests and tensorflow_addons/layers/tests. Start by tracing pytest's test-module import and path handling around the reported import-file mismatch, then determine whether unique paths can be supported; done should include a defined outcome for this case and regression coverage if behavior changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.