Skip to content

Commit

Permalink
Add workaround for pytest recursion (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen authored Dec 11, 2024
1 parent b05ca15 commit 36d0efc
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: ["3.9"]
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]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
pytest-version: [6.2.5, 7.0.1, 7.4.4, 8.0.2, 8.3.4]
exclude:
# some tests still fail for macOS/Python 3.13
- python-version: "3.13"
os: macOS-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -126,20 +130,15 @@ jobs:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -U pytest==${{ matrix.pytest-version }}
python -m pip install opentimelineio pandas parquet pyarrow
python -m pip install pandas parquet pyarrow
python -m pip install -e .
if [[ '${{ matrix.pytest-version }}' == '4.0.2' ]]; then
python -m pip install -U attrs==19.1.0
fi
shell: bash
- name: Run pytest tests
run: |
echo "$(python -m pytest pyfakefs/pytest_tests/pytest_plugin_failing_helper.py)" > ./testresult.txt
python -m pytest pyfakefs/pytest_tests
if [[ '${{ matrix.pytest-version }}' > '3.0.0' ]]; then
cd pyfakefs/pytest_tests/ns_package
python -m pytest --log-cli-level=INFO test
fi
pytest pyfakefs/pytest_tests
cd pyfakefs/pytest_tests/ns_package
pytest --log-cli-level=INFO test
shell: bash

dependency-check:
Expand Down
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ The released versions correspond to PyPI releases.
### Fixes
* fixed a regression in version 5.7.2 that `tempfile` was not patched after pause/resume
(POSIX only, see [#1098](../../issues/1098))
* added workaround for a recursion occurring if using pytest under Windows and Python >= 3.12
(see [#1096](../../issues/1096))

### Infrastructure
* run pytest-specific tests for all supported Python versions
* pytest is only supported for versions >= 6.2.5, earlier version do not work
due to a pytest issue - adapted tests and documentation

## [Version 5.7.2](https://pypi.python.org/pypi/pyfakefs/5.7.2) (2024-12-01)
Fixes some problems with patching.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ provides some additional features:
pyfakefs works with CPython 3.7 and above, on Linux, Windows and macOS, and
with PyPy3.

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

pyfakefs will not work with Python libraries that use C libraries to access the
Expand Down
7 changes: 5 additions & 2 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,10 @@ def updatecache(self, filename, module_globals=None):
"""Calls the original linecache.updatecache making sure no fake OS calls
are used."""
with use_original_os():
return self.linecache_updatecache(filename, module_globals)
# workaround for updatecache problem with pytest under Windows, see #1096
if not filename.endswith(r"pytest.exe\__main__.py"):
return self.linecache_updatecache(filename, module_globals)
return []

@classmethod
def clear_fs_cache(cls) -> None:
Expand Down Expand Up @@ -1010,7 +1013,7 @@ def start_patching(self) -> None:
self._patching = True
self._paused = False

if sys.version_info >= (3, 13):
if sys.version_info >= (3, 12):
# in linecache, 'os' is now imported locally, which involves the
# dynamic patcher, therefore we patch the affected functions
self.linecache_updatecache = linecache.updatecache
Expand Down
2 changes: 1 addition & 1 deletion pyfakefs/pytest_tests/pytest_module_fixture_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def test_fs_uses_fs_module1():


def test_fs_uses_fs_module2(fs):
# check that testing was not stopped by the first test
# check that patching was not stopped by the first test
assert os.path.exists(os.path.join("foo", "bar"))
8 changes: 8 additions & 0 deletions pyfakefs/pytest_tests/pytest_plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,11 @@ def test_switch_to_linux(fs):
def test_switch_to_macos(fs):
fs.os = OSType.MACOS
assert os.path.exists(tempfile.gettempdir())


def test_updatecache_problem(fs):
# regression test for #1096
filename = r"C:\source_file"
fs.create_file(filename)
with open(filename):
assert True
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest>=3.0.0
pytest>=6.2.5

0 comments on commit 36d0efc

Please sign in to comment.