Skip to content

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Dec 12, 2024

This is a backport of PR #13053 as merged into main (28e1e25).

Regression in #12716

In short: PathFinder.find_spec received the argument /cow/moo but loaded /cow/moo/moo.py instead.

Trigger conditions:

  1. /cow/moo/moo.py exists (a file and directory with the same name).
  2. /cow/moo/test_moo.py exists (test case resides in the directory).

When pytest loads test files in importlib mode, it continues recursive loading upward:

  • When loading cow.moo, it should return a namespace but unexpectedly returns a module.
  • When loading cow.moo.moo, it should return a module but unexpectedly returns a namespace.

Complete example: [GitHub repository](https://github.com/dongfangtianyu/pytest_importlib_issue)

  • main.py: Reproduces the error.
  • debug.py: Demonstrates the behavior of PathFinder.find_spec.

Context:
#12592 (comment)
#12592 (comment)

Regression in #12716

In short: `PathFinder.find_spec` received the argument `/cow/moo` but loaded `/cow/moo/moo.py` instead.

**Trigger conditions:**
1. `/cow/moo/moo.py` exists (a file and directory with the same name).
2. `/cow/moo/test_moo.py` exists (test case resides in the directory).

When pytest loads test files in `importlib` mode, it continues recursive loading upward:
- When loading `cow.moo`, it should return a namespace but unexpectedly returns a module.
- When loading `cow.moo.moo`, it should return a module but unexpectedly returns a namespace.

**Complete example:** [[GitHub repository](https://github.com/dongfangtianyu/pytest_importlib_issue)](https://github.com/dongfangtianyu/pytest_importlib_issue)
- `main.py`: Reproduces the error.
- `debug.py`: Demonstrates the behavior of `PathFinder.find_spec`.

**Context:**
#12592 (comment)
#12592 (comment)

---------

Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
(cherry picked from commit 28e1e25)
@nicoddemus
Copy link
Member

We can ignore the pluggy-main job for now.

@nicoddemus nicoddemus merged commit 4e7af35 into 8.3.x Dec 12, 2024
27 of 29 checks passed
@nicoddemus nicoddemus deleted the patchback/backports/8.3.x/28e1e25a6782513db8a2963bd5ed5a9d66682f86/pr-13053 branch December 12, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants