Skip to content

Commit 36d0efc

Browse files
Add workaround for pytest recursion (#1100)
1 parent b05ca15 commit 36d0efc

File tree

7 files changed

+33
-16
lines changed

7 files changed

+33
-16
lines changed

.github/workflows/testsuite.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@ jobs:
113113
fail-fast: false
114114
matrix:
115115
os: [ubuntu-latest, macOS-latest, windows-latest]
116-
python-version: ["3.9"]
117-
pytest-version: [3.0.0, 3.5.1, 4.0.2, 4.5.0, 5.0.1, 5.4.3, 6.0.2, 6.2.5, 7.0.1, 7.4.4, 8.0.2, 8.1.2, 8.2.0]
116+
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
117+
pytest-version: [6.2.5, 7.0.1, 7.4.4, 8.0.2, 8.3.4]
118+
exclude:
119+
# some tests still fail for macOS/Python 3.13
120+
- python-version: "3.13"
121+
os: macOS-latest
118122
steps:
119123
- uses: actions/checkout@v4
120124
- name: Set up Python ${{ matrix.python-version }}
@@ -126,20 +130,15 @@ jobs:
126130
python -m pip install --upgrade pip
127131
python -m pip install -r requirements.txt
128132
python -m pip install -U pytest==${{ matrix.pytest-version }}
129-
python -m pip install opentimelineio pandas parquet pyarrow
133+
python -m pip install pandas parquet pyarrow
130134
python -m pip install -e .
131-
if [[ '${{ matrix.pytest-version }}' == '4.0.2' ]]; then
132-
python -m pip install -U attrs==19.1.0
133-
fi
134135
shell: bash
135136
- name: Run pytest tests
136137
run: |
137138
echo "$(python -m pytest pyfakefs/pytest_tests/pytest_plugin_failing_helper.py)" > ./testresult.txt
138-
python -m pytest pyfakefs/pytest_tests
139-
if [[ '${{ matrix.pytest-version }}' > '3.0.0' ]]; then
140-
cd pyfakefs/pytest_tests/ns_package
141-
python -m pytest --log-cli-level=INFO test
142-
fi
139+
pytest pyfakefs/pytest_tests
140+
cd pyfakefs/pytest_tests/ns_package
141+
pytest --log-cli-level=INFO test
143142
shell: bash
144143

145144
dependency-check:

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ The released versions correspond to PyPI releases.
1717
### Fixes
1818
* fixed a regression in version 5.7.2 that `tempfile` was not patched after pause/resume
1919
(POSIX only, see [#1098](../../issues/1098))
20+
* added workaround for a recursion occurring if using pytest under Windows and Python >= 3.12
21+
(see [#1096](../../issues/1096))
22+
23+
### Infrastructure
24+
* run pytest-specific tests for all supported Python versions
25+
* pytest is only supported for versions >= 6.2.5, earlier version do not work
26+
due to a pytest issue - adapted tests and documentation
2027

2128
## [Version 5.7.2](https://pypi.python.org/pypi/pyfakefs/5.7.2) (2024-12-01)
2229
Fixes some problems with patching.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ provides some additional features:
5858
pyfakefs works with CPython 3.7 and above, on Linux, Windows and macOS, and
5959
with PyPy3.
6060

61-
pyfakefs works with [pytest](http://doc.pytest.org) version 3.0.0 or above,
61+
pyfakefs works with [pytest](http://doc.pytest.org) version 6.2.5 or above,
6262
though a current version is recommended.
6363

6464
pyfakefs will not work with Python libraries that use C libraries to access the

pyfakefs/fake_filesystem_unittest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,10 @@ def updatecache(self, filename, module_globals=None):
700700
"""Calls the original linecache.updatecache making sure no fake OS calls
701701
are used."""
702702
with use_original_os():
703-
return self.linecache_updatecache(filename, module_globals)
703+
# workaround for updatecache problem with pytest under Windows, see #1096
704+
if not filename.endswith(r"pytest.exe\__main__.py"):
705+
return self.linecache_updatecache(filename, module_globals)
706+
return []
704707

705708
@classmethod
706709
def clear_fs_cache(cls) -> None:
@@ -1010,7 +1013,7 @@ def start_patching(self) -> None:
10101013
self._patching = True
10111014
self._paused = False
10121015

1013-
if sys.version_info >= (3, 13):
1016+
if sys.version_info >= (3, 12):
10141017
# in linecache, 'os' is now imported locally, which involves the
10151018
# dynamic patcher, therefore we patch the affected functions
10161019
self.linecache_updatecache = linecache.updatecache

pyfakefs/pytest_tests/pytest_module_fixture_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ def test_fs_uses_fs_module1():
2727

2828

2929
def test_fs_uses_fs_module2(fs):
30-
# check that testing was not stopped by the first test
30+
# check that patching was not stopped by the first test
3131
assert os.path.exists(os.path.join("foo", "bar"))

pyfakefs/pytest_tests/pytest_plugin_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,11 @@ def test_switch_to_linux(fs):
7777
def test_switch_to_macos(fs):
7878
fs.os = OSType.MACOS
7979
assert os.path.exists(tempfile.gettempdir())
80+
81+
82+
def test_updatecache_problem(fs):
83+
# regression test for #1096
84+
filename = r"C:\source_file"
85+
fs.create_file(filename)
86+
with open(filename):
87+
assert True

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pytest>=3.0.0
1+
pytest>=6.2.5

0 commit comments

Comments
 (0)