-
Notifications
You must be signed in to change notification settings - Fork 92
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
INTERNALERROR /path/to/file is not in the subpath of '\\/path/to/file' #814
Comments
Thanks for the report! As for the broken issue template - I actually noticed this in the last bug report, but forgot to check it out. Thanks for the reminder! |
Yeah thank you! Sounds good. I also came up with a simpler repro today, simply setting the import pyfakefs.fake_filesystem
def test_foo(fs) -> None:
fs.os = pyfakefs.fake_filesystem.OSType.WINDOWS Running like this yields the error: > pytest test/repo/test/test_play.py -s --log-cli-level=DEBUG
=============================================================================================================== test session starts ===============================================================================================================
platform darwin -- Python 3.10.9, pytest-7.2.2, pluggy-1.0.0
rootdir: /Users/user/code/repo/test, configfile: pyproject.toml
plugins: pyfakefs-5.2.2, mock-3.10.0, subtests-0.10.0
collected 1 item
test/repo/test/test_play.py::test_foo
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 270, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 324, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 349, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/runner.py", line 112, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/runner.py", line 131, in runtestprotocol
INTERNALERROR> reports.append(call_and_report(item, "call", log))
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/runner.py", line 224, in call_and_report
INTERNALERROR> hook.pytest_runtest_logreport(report=report)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/terminal.py", line 551, in pytest_runtest_logreport
INTERNALERROR> line = self._locationline(rep.nodeid, *rep.location)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/terminal.py", line 878, in _locationline
INTERNALERROR> res = mkrel(nodeid)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/terminal.py", line 868, in mkrel
INTERNALERROR> line = self.config.cwd_relative_nodeid(nodeid)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1104, in cwd_relative_nodeid
INTERNALERROR> nodeid = bestrelpath(self.invocation_params.dir, fullpath)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/pathlib.py", line 710, in bestrelpath
INTERNALERROR> reldirectory = directory.relative_to(base)
INTERNALERROR> File "/Users/user/.pyenv/versions/3.10.9/lib/python3.10/pathlib.py", line 818, in relative_to
INTERNALERROR> raise ValueError("{!r} is not in the subpath of {!r}"
INTERNALERROR> ValueError: '/Users/user/code/repo' is not in the subpath of '\\/Users/user/code/repo' OR one path is relative and the other is absolute.
Traceback (most recent call last):
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 1618, in get_object_from_normpath
target = target.get_entry(component) # type: ignore
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_file.py", line 542, in get_entry
return self.entries[to_string(pathname_name)]
KeyError: 'Users'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/code/repo/venv/bin/pytest", line 8, in <module>
sys.exit(console_main())
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 190, in console_main
code = main()
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 167, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 317, in pytest_cmdline_main
return wrap_session(config, _main)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 302, in wrap_session
os.chdir(session.startpath)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_os.py", line 1354, in wrapped
return f(*args, **kwargs)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_os.py", line 421, in chdir
self.filesystem.confirmdir(path)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 2810, in confirmdir
self.resolve(target_directory, check_owner=check_owner),
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 1692, in resolve
return self.get_object_from_normpath(
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 1627, in get_object_from_normpath
self.raise_os_error(errno.ENOENT, path)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 418, in raise_os_error
raise OSError(err_no, message, filename)
FileNotFoundError: [Errno 2] No such file or directory in the fake filesystem: 'C:\\Users\\user\\code\\repo' |
Ok, I think I know what the problem is - I think this is actually a regression. |
- the temp dir is now created during filesystem initialization instead of at patcher setup - fixes pytest-dev#814
- the temp dir is now created during filesystem initialization instead of at patcher setup - fixes pytest-dev#814
If this is a regression, what was the previous code that was creating a temporary directory and adding a symlink to the fake filesystem, as is suggested for the pull request? |
The code to create the temp directory previously was in the patcher. The regression happened because I added a filesystem reset in the os setters, and this removed the temp directory. |
- the temp dir is now created during filesystem initialization instead of at patcher setup if configured - this is only done by default if created from the Patcher - fixes pytest-dev#814
* Re-create the temp directory on resetting the filesystem - the temp dir is now created during filesystem initialization instead of at patcher setup if configured - this is only done by default if created from the Patcher - fixes #814 * Call reset() from __init__ - change from review
I am just giving this a whirl right now! I don't know that #818 actually fixed the issue though. I am still getting the same > pip install ~/code/pyfakefs
Looking in indexes: https://pypi.org/simple
Processing /Users/user/code/pyfakefs
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyfakefs
Building wheel for pyfakefs (pyproject.toml) ... done
Created wheel for pyfakefs: filename=pyfakefs-5.3.dev0-py3-none-any.whl size=205504 sha256=blah
Stored in directory: /private/var/folders/78/blah/T/pip-ephem-wheel-cache-or80khnp/wheels/17/ef/87/blah
Successfully built pyfakefs
Installing collected packages: pyfakefs
Successfully installed pyfakefs-5.3.dev0 With this file: import pyfakefs.fake_filesystem
def test_foo(fs) -> None:
fs.os = pyfakefs.fake_filesystem.OSType.WINDOWS Running like so: > pytest test/repo/test/test_play.py -s --log-cli-level=DEBUG
=============================================================================================================== test session starts ===============================================================================================================
platform darwin -- Python 3.10.9, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/user/code/repo/test
configfile: pyproject.toml
plugins: pyfakefs-5.3.dev0, mock-3.10.0, subtests-0.10.0
collected 1 item
test/repo/test/test_play.py::test_foo
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 323, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 348, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/runner.py", line 114, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/runner.py", line 133, in runtestprotocol
INTERNALERROR> reports.append(call_and_report(item, "call", log))
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/runner.py", line 226, in call_and_report
INTERNALERROR> hook.pytest_runtest_logreport(report=report)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/terminal.py", line 557, in pytest_runtest_logreport
INTERNALERROR> line = self._locationline(rep.nodeid, *rep.location)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/terminal.py", line 882, in _locationline
INTERNALERROR> res = mkrel(nodeid)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/terminal.py", line 872, in mkrel
INTERNALERROR> line = self.config.cwd_relative_nodeid(nodeid)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1110, in cwd_relative_nodeid
INTERNALERROR> nodeid = bestrelpath(self.invocation_params.dir, fullpath)
INTERNALERROR> File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/pathlib.py", line 741, in bestrelpath
INTERNALERROR> reldirectory = directory.relative_to(base)
INTERNALERROR> File "/Users/user/.pyenv/versions/3.10.9/lib/python3.10/pathlib.py", line 818, in relative_to
INTERNALERROR> raise ValueError("{!r} is not in the subpath of {!r}"
INTERNALERROR> ValueError: '/Users/user/code/repo' is not in the subpath of '\\/Users/user/code/repo' OR one path is relative and the other is absolute.
Traceback (most recent call last):
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 1628, in get_object_from_normpath
target = target.get_entry(component) # type: ignore
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_file.py", line 542, in get_entry
return self.entries[to_string(pathname_name)]
KeyError: 'Users'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/code/repo/venv/bin/pytest", line 8, in <module>
sys.exit(console_main())
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 189, in console_main
code = main()
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 166, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 316, in pytest_cmdline_main
return wrap_session(config, _main)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/_pytest/main.py", line 301, in wrap_session
os.chdir(session.startpath)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_os.py", line 1354, in wrapped
return f(*args, **kwargs)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_os.py", line 421, in chdir
self.filesystem.confirmdir(path)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 2820, in confirmdir
self.resolve(target_directory, check_owner=check_owner),
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 1702, in resolve
return self.get_object_from_normpath(
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 1637, in get_object_from_normpath
self.raise_os_error(errno.ENOENT, path)
File "/Users/user/code/repo/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 428, in raise_os_error
raise OSError(err_no, message, filename)
FileNotFoundError: [Errno 2] No such file or directory in the fake filesystem: 'C:\\Users\\user\\code\\repo' Any ideas? |
I just noticed that the
You mean after it was merged, right? |
Thanks for reopening! I see what you mean per
Yeah, I have https://github.com/pytest-dev/pyfakefs/tree/b79f55616c2b757a4376d6e9b46472713189f344 checked out |
Hm, I added the tests in #820, and they all pass. The test in question is just: def test_switch_to_windows(fs):
fs.os = OSType.WINDOWS
assert os.path.exists(tempfile.gettempdir()) which to me seems to be exactly what you are doing. |
It did not, the tests all pass for macOS. Can you please check what may be different in your environment? I really have no idea how to test this without a Mac and without reproducibility in CI.... |
I am using One important comment I can add is the
This is the relevant trace in the INTERNALERROR> File "/Users/user/.pyenv/versions/3.10.9/lib/python3.10/pathlib.py", line 818, in relative_to
INTERNALERROR> raise ValueError("{!r} is not in the subpath of {!r}"
INTERNALERROR> ValueError: '/Users/user/code/repo' is not in the subpath of '\\/Users/user/code/repo' OR one path is relative and the other is absolute. It looks like |
Ok, thank you, that is a good hint - I'm done for today, will see if I can find out more tomorrow. |
Yes, I think you are right, and the problem here is indeed related to the mixup of different filesystem paths. |
@jamesbraza - I'm struggling to reproduce your problem, even with a namespace package, but maybe I'm doing something wrong. Have you by any chance a small reproducible failing example (could also be a repository), so I can be sure to test the correct thing? |
@mrbean-bremen yeah sure, I can make one by 5/19/2023 (next Friday) 👌 Sorry I didn't have a more complete repro for this creation of this ticket, didn't realize it would be tough to reproduce |
Thank you! I may just have made some dumb mistake, but as I don't have a Mac, it is good to have a reliable reproducable test that I can run via CI. |
Okay @mrbean-bremen I have a working reproduction via macOS. One thing that's important: using the Control Group: Working
Where import pyfakefs.fake_filesystem
def test_foo(fs) -> None:
fs.os = pyfakefs.fake_filesystem.OSType.WINDOWS No errors, yay! (venv) ➜ repo pytest --log-cli-level=DEBUG test
=============================================================================================================== test session starts ===============================================================================================================
platform darwin -- Python 3.10.9, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/user/code/repo
plugins: pyfakefs-5.2.2
collected 1 item
test/repo/test/test_file.py::test_foo PASSED [100%]
================================================================================================================ 1 passed in 0.02s ================================================================================================================ Exposing the Bug Now, let's break it 😈 by adding an empty
(venv) ➜ repo pytest --log-cli-level=DEBUG test
=============================================================================================================== test session starts ===============================================================================================================
platform darwin -- Python 3.10.9, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/user/code/repo/test
plugins: pyfakefs-5.2.2
collected 1 item
test/repo/test/test_file.py::test_foo Traceback (most recent call last):
File "/path/to/venv/lib/python3.10/site-packages/_pytest/main.py", line 269, in wrap_session
session.exitstatus = doit(config, session) or 0
File "/path/to/venv/lib/python3.10/site-packages/_pytest/main.py", line 323, in _main
config.hook.pytest_runtestloop(session=session)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/main.py", line 348, in pytest_runtestloop
item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/runner.py", line 114, in pytest_runtest_protocol
runtestprotocol(item, nextitem=nextitem)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/runner.py", line 133, in runtestprotocol
reports.append(call_and_report(item, "call", log))
File "/path/to/venv/lib/python3.10/site-packages/_pytest/runner.py", line 226, in call_and_report
hook.pytest_runtest_logreport(report=report)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/terminal.py", line 557, in pytest_runtest_logreport
line = self._locationline(rep.nodeid, *rep.location)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/terminal.py", line 882, in _locationline
res = mkrel(nodeid)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/terminal.py", line 872, in mkrel
line = self.config.cwd_relative_nodeid(nodeid)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1110, in cwd_relative_nodeid
nodeid = bestrelpath(self.invocation_params.dir, fullpath)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/pathlib.py", line 741, in bestrelpath
reldirectory = directory.relative_to(base)
File "/Users/user/.pyenv/versions/3.10.9/lib/python3.10/pathlib.py", line 818, in relative_to
raise ValueError("{!r} is not in the subpath of {!r}"
ValueError: '/Users/user/code/repo' is not in the subpath of '\\/Users/user/code/repo' OR one path is relative and the other is absolute.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/path/to/venv/lib/python3.10/site-packages/_pytest/main.py", line 289, in wrap_session
config.notify_exception(excinfo, config.option)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1100, in notify_exception
res = self.hook.pytest_internalerror(excrepr=excrepr, excinfo=excinfo)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/capture.py", line 888, in pytest_internalerror
self.stop_global_capturing()
File "/path/to/venv/lib/python3.10/site-packages/_pytest/capture.py", line 756, in stop_global_capturing
self._global_capturing.stop_capturing()
File "/path/to/venv/lib/python3.10/site-packages/_pytest/capture.py", line 673, in stop_capturing
self.out.done()
File "/path/to/venv/lib/python3.10/site-packages/_pytest/capture.py", line 509, in done
os.close(self.targetfd_save)
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_os.py", line 1354, in wrapped
return f(*args, **kwargs)
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_os.py", line 308, in close
file_handle = self.filesystem.get_open_file(fd)
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 857, in get_open_file
self.raise_os_error(errno.EBADF, str(file_des))
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 418, in raise_os_error
raise OSError(err_no, message, filename)
OSError: [Errno 9] Bad file descriptor in the fake filesystem: '5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 1618, in get_object_from_normpath
target = target.get_entry(component) # type: ignore
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_file.py", line 542, in get_entry
return self.entries[to_string(pathname_name)]
KeyError: 'Users'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/path/to/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 166, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/path/to/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/main.py", line 316, in pytest_cmdline_main
return wrap_session(config, _main)
File "/path/to/venv/lib/python3.10/site-packages/_pytest/main.py", line 301, in wrap_session
os.chdir(session.startpath)
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_os.py", line 1354, in wrapped
return f(*args, **kwargs)
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_os.py", line 421, in chdir
self.filesystem.confirmdir(path)
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 2810, in confirmdir
self.resolve(target_directory, check_owner=check_owner),
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 1692, in resolve
return self.get_object_from_normpath(
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 1627, in get_object_from_normpath
self.raise_os_error(errno.ENOENT, path)
File "/path/to/venv/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 418, in raise_os_error
raise OSError(err_no, message, filename)
FileNotFoundError: [Errno 2] No such file or directory in the fake filesystem: 'C:\\Users\\user\\code\\repo'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/path/to/venv/bin/pytest", line 8, in <module>
sys.exit(console_main())
File "/path/to/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 189, in console_main
code = main()
File "/path/to/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 174, in main
config._ensure_unconfigure()
File "/path/to/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1055, in _ensure_unconfigure
fin()
File "/path/to/venv/lib/python3.10/site-packages/_pytest/capture.py", line 756, in stop_global_capturing
self._global_capturing.stop_capturing()
File "/path/to/venv/lib/python3.10/site-packages/_pytest/capture.py", line 670, in stop_capturing
raise ValueError("was already stopped")
ValueError: was already stopped Hope that helps, please let me know if you need anything else! 👌 Just noticed this error: |
Thanks for the effort! I will have a closer look as soon as I find the time - probably at the end of this week. |
I had another look, and it seems that this can indeed be prevented by excluding some import pyfakefs.fake_filesystem
from pyfakefs.fake_filesystem_unittest import Patcher
from _pytest import capture, pathlib
Patcher.SKIPMODULES.add(capture)
Patcher.SKIPMODULES.add(pathlib)
def test_foo(fs) -> None:
fs.os = pyfakefs.fake_filesystem.OSType.WINDOWS The additional skip modules would be added to the pytest plugin, but you can test it locally this way. |
That works, thank you! 🥳 Just to share, it seems like we can get away with skipping just
|
Thanks - I will skip only |
- fixes some specific tests in namespace packages - fixes pytest-dev#814
- fixes some specific tests in namespace packages - fixes #814
Describe the bug
In unit testing, I need to emulate a Windows OS. My base machine is macOS.
When using
pyfakefs.fake_filesystem.OSType.WINDOWS
+tempfile
+--log-cli-level=DEBUG
, I get the below internal error.How To Reproduce
Outputs the following:
Your environment
I have
pyfakefs==5.2.2
. Note the current version printing from the issue template is broken.The text was updated successfully, but these errors were encountered: