Commit 4e7af35
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)
Co-authored-by: dongfangtianyu <7629022+dongfangtianyu@users.noreply.github.com>
1 parent 179b690 commit 4e7af35
File tree
3 files changed
+39
-3
lines changed- changelog
- src/_pytest
- testing
3 files changed
+39
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
694 | 694 | | |
695 | 695 | | |
696 | 696 | | |
697 | | - | |
698 | | - | |
699 | | - | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
700 | 707 | | |
701 | 708 | | |
702 | 709 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1498 | 1498 | | |
1499 | 1499 | | |
1500 | 1500 | | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
1501 | 1529 | | |
1502 | 1530 | | |
1503 | 1531 | | |
| |||
0 commit comments