-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad assertion with pytest 7.0.0 & fs fixture #666
Comments
Thanks for the report - this is weird! From the first glance, it looks like pytest itself uses some file access while pyfakefs is still active, e.g. fs access is patched. |
Ok, for my own reference: def bestrelpath(directory: Path, dest: Path) -> str:
"""Return a string which is a relative path from directory to dest such
that directory/bestrelpath == dest.
The paths must be either both absolute or both relative.
If no such path can be determined, returns dest.
"""
assert isinstance(directory, Path) # new in pytest 7
assert isinstance(dest, Path)
... # unchanged code If commenting out these asserts in pytest, the test passes. The asserts have been added for this issue to make sure pathlib Paths are used and not strings. As for the fix, I don't have an idea yet - the clean fix would be to make sure that nothing is patched at that point, but I'm not sure how to achieve this. |
Thanks for your feedback! :)
No problem. There is a workaround for the moment. 👍 |
- avoids the use of FakePathLibPath in pathlib - add _pytest.pathlib to skipped modules, fake isinstance check for RealPathlibPathModule - prevents issue with _pytest.pathlib in pytest 7.0.0, which would cause all tests with fs fixture to fail - see pytest-dev#666
- avoids the use of FakePathLibPath in pathlib - add _pytest.pathlib to skipped modules, fake isinstance check for RealPathlibPathModule - prevents issue with _pytest.pathlib in pytest 7.0.0, which would cause all tests with fs fixture to fail - see #666
…ePathLibPath in pathlib - add _pytest.pathlib to skipped modules, fake isinstance check for RealPathlibPathModule - prevents issue with _pytest.pathlib in pytest 7.0.0, which would cause all tests with fs fixture to fail - see #666
@Wescoeur - should be fixed in master now - please check if it works for you! |
@mrbean-bremen Hi, I confirm, it's fixed on my side with the last commit! Thx! 👍 |
Thanks - will make a patch release tonight in this case! |
- fixes pytest-dev#666 without the need to skip _pytest.pathlib patching - add module and session scoped fs fixtures
- fixes pytest-dev#666 without the need to skip _pytest.pathlib patching - add module and session scoped fs fixtures - fixes pytest-dev#684
Describe the bug
With the new pytest version (7.0.0), we can't run pytest/pyfakes using this command line with a subfolder:
Instead we must use:
Otherwise we have this trace:
How To Reproduce
A minimal code is present here to reproduce the bug: https://github.com/Wescoeur/pyfakefs-pytest-bug
Use directly
pytest tests/
in the root folder of this repo.Note: If
log_cli
is disabled inpytest.ini
, the assertion of the stacktrace is always true and we don't have the issue. The issue is triggered whenlog_cli
is true and when thefs
fixture is used in a test like in:Your environment
Linux-5.16.1-arch1-1-x86_64-with-glibc2.33
Python 3.10.1 (main, Dec 18 2021, 23:53:45) [GCC 11.1.0]
pyfakefs 4.5.4
The text was updated successfully, but these errors were encountered: