Skip to content
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

Test error on Ubuntu: Module-scoped fake filesystem fixture not found #687

Closed
nicolashainaux opened this issue Jul 13, 2022 · 9 comments
Closed

Comments

@nicolashainaux
Copy link

Describe the bug
If I run pytest -vv -x, (-vv is to get verbose output, -x is to stop pytest at first error) I get the following error:

pyfakefs/tests/fake_filesystem_unittest_test.py::TestModuleScopedFsWithTmpdir::test_fail ERROR                                                                                                 [ 21%]

=============================================================================================== ERRORS ===============================================================================================
______________________________________________________________________ ERROR at setup of TestModuleScopedFsWithTmpdir.test_fail ______________________________________________________________________
file /home/sophie/.local/dev/pyfakefs/pyfakefs/tests/fake_filesystem_unittest_test.py, line 889
      def test_fail(self, fs_module):
E       fixture 'fs_module' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, cov, doctest_namespace, mock, mocker, monkeypatch, no_cover, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, test_internal, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/home/sophie/.local/dev/pyfakefs/pyfakefs/tests/fake_filesystem_unittest_test.py:889
====================================================================================== short test summary info =======================================================================================
ERROR pyfakefs/tests/fake_filesystem_unittest_test.py::TestModuleScopedFsWithTmpdir::test_fail
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================================== 403 passed, 39 skipped, 4 xfailed, 1 error in 2.06s =========================================================================

I followed the given advice (hence pytest --fixtures pyfakefs/pytest_plugin.py), but everything was green (it found the module-scoped fixture):

---------------------------------------------------------------------------- fixtures defined from pyfakefs.pytest_plugin ----------------------------------------------------------------------------
fs -- pyfakefs/pytest_plugin.py:21
    Fake filesystem. 

fs_module [module scope] -- pyfakefs/pytest_plugin.py:34
    Module-scoped fake filesystem fixture. 

fs_session [session scope] -- pyfakefs/pytest_plugin.py:46
    Session-scoped fake filesystem fixture. 

First try was with older pytest (the focal packaged one, 4.6.9), but I have got the same result with latest pytest (>7.0).

I am not 100% sure this is a bug: maybe I haven't run the right tests? Or not the right way?
I have looked for the same test in your github actions (Latest Ubuntu, python3.8), but I have not found it.

How To Reproduce
Just run pytest -vv -x in the cloned repo (master branch)

Your environment

Linux-5.4.0-122-generic-x86_64-with-glibc2.31

Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0]

pyfakefs 4.7.dev0

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Jul 13, 2022

Looks like I put this test into the wrong module. The test assumes that pyfakefs is installed as a package, so that the fixtures are registered. This is only assumed for the pytest_plugin_test module where this test belongs, and which is not run by default - I will move it there. I did not notice this, as the CI tests do install pyfakefs, and I locally use a developer install.

Thanks for the report - I will fix this in master, and then look at the other Pytho 3.11 related problems that have been reported before making a patch release.

@mrbean-bremen
Copy link
Member

Please check if it works with current master.

@nicolashainaux
Copy link
Author

Thanks for your quick patch!
Unfortunately, it still fails the same way. I installed pyfakefs in a venv, to make sure it was installed (python setup.py install and python setup.py develop is the right way, I guess), but still:

(py38) pyfakefs [master|+1*330] $ pytest -vv -x
=============================================== test session starts ================================================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-0.13.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/sophie/.local/dev/pyfakefs
plugins: mock-1.10.4, cov-2.8.1
collected 2068 items                                                                                               

pyfakefs/pytest_tests/pytest_check_failed_plugin_test.py::test_failed_testresult_stacktrace SKIPPED (Only run in CI tests) [  0%]
pyfakefs/pytest_tests/pytest_fixture_param_test.py::test_example_file_failing XFAIL                          [  0%]
pyfakefs/pytest_tests/pytest_fixture_param_test.py::test_example_file_passing_using_parametrized_fixture[fs0] PASSED [  0%]
pyfakefs/pytest_tests/pytest_fixture_param_test.py::test_twice_chdir PASSED                                  [  0%]
pyfakefs/pytest_tests/pytest_fixture_test.py::test_example_file_failing XFAIL                                [  0%]
pyfakefs/pytest_tests/pytest_fixture_test.py::test_example_file_passing_using_fixture PASSED                 [  0%]
pyfakefs/pytest_tests/pytest_fixture_test.py::test_example_file_passing_using_patcher PASSED                 [  0%]
pyfakefs/pytest_tests/pytest_plugin_test.py::test_fs_fixture PASSED                                          [  0%]
pyfakefs/pytest_tests/pytest_plugin_test.py::test_fs_fixture_alias PASSED                                    [  0%]
pyfakefs/pytest_tests/pytest_plugin_test.py::test_both_fixtures PASSED                                       [  0%]
pyfakefs/pytest_tests/pytest_plugin_test.py::test_pause_resume PASSED                                        [  0%]
pyfakefs/pytest_tests/pytest_plugin_test.py::test_pause_resume_contextmanager PASSED                         [  0%]
pyfakefs/pytest_tests/pytest_plugin_test.py::TestModuleScopedFsWithTmpdir::test_fail ERROR                   [  0%]

====================================================== ERRORS ======================================================
_____________________________ ERROR at setup of TestModuleScopedFsWithTmpdir.test_fail _____________________________
file /home/sophie/.local/dev/pyfakefs/pyfakefs/pytest_tests/pytest_plugin_test.py, line 62
      def test_fail(self, fs_module):
E       fixture 'fs_module' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, cov, doctest_namespace, fake_filesystem, fs, fs_reload_example, mock, mocker, monkeypatch, no_cover, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, test_internal, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/home/sophie/.local/dev/pyfakefs/pyfakefs/pytest_tests/pytest_plugin_test.py:62
============================================= short test summary info ==============================================
ERROR pyfakefs/pytest_tests/pytest_plugin_test.py::TestModuleScopedFsWithTmpdir::test_fail
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================= 9 passed, 1 skipped, 2 xfailed, 1 error in 0.54s =================================

@mrbean-bremen mrbean-bremen reopened this Jul 13, 2022
@mrbean-bremen
Copy link
Member

Ok, thank you - now I understood the problem, I fixed only half of it. I had an extra import for fs added in the conftest.py. This allowed these tests to to run without pyfakefs installed, and I forgot to add the same for fs_module. I probably have to remove installing the pyfakefs package in the CI tests to find these kind of problems. Thanks again!

@mrbean-bremen
Copy link
Member

Ok, second try - please check again!

github-actions bot pushed a commit that referenced this issue Jul 13, 2022
@nicolashainaux
Copy link
Author

Well, the tests do pass, but there's a strange exception at the end (sophie being the current user name):

pyfakefs [master|+1*330] $ pytest -x
=========================================================== test session starts ============================================================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-0.13.0
rootdir: /home/sophie/.local/dev/pyfakefs
plugins: mock-1.10.4, cov-2.8.1
collected 2068 items                                                                                                                       

pyfakefs/pytest_tests/pytest_check_failed_plugin_test.py s                                                                           [  0%]
pyfakefs/pytest_tests/pytest_fixture_param_test.py x..                                                                               [  0%]
pyfakefs/pytest_tests/pytest_fixture_test.py x..                                                                                     [  0%]
pyfakefs/pytest_tests/pytest_plugin_test.py ......                                                                                   [  0%]
pyfakefs/tests/dynamic_patch_test.py .....                                                                                           [  0%]
pyfakefs/tests/example_test.py .......s                                                                                              [  1%]
pyfakefs/tests/fake_filesystem_glob_test.py .........                                                                                [  1%]
pyfakefs/tests/fake_filesystem_shutil_test.py ................s...ssssssssssssssssssssss...........sssssssssss                       [  4%]
pyfakefs/tests/fake_filesystem_test.py ............................................................................................. [  9%]
.............................................s.................................s.................................................... [ 15%]
......................................                                                                                               [ 17%]
pyfakefs/tests/fake_filesystem_unittest_test.py .........................x...............................x.......................... [ 21%]
s                                                                                                                                    [ 21%]
pyfakefs/tests/fake_filesystem_vs_real_test.py ...........................                                                           [ 22%]
pyfakefs/tests/fake_open_test.py .......................................................................ssssssssssssssssssssssssssss [ 27%]
sssssssssssssssssssssssssssssssssssssssssss...sss..sss............ssssssssssss..........ssssssssss.....s..ssssssss.....sssss.....sss [ 34%]
..ss.....sssss..................ssssssssssssssssss                                                                                   [ 36%]
pyfakefs/tests/fake_os_test.py ..................................................................................................... [ 41%]
.................................................................................................................................... [ 47%]
................................................ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 54%]
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 60%]
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss................................................................... [ 66%]
................sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss.................s............... [ 73%]
....................s......sssssssssssssssssssssssssssssssssssssssssssssssss...........sssssssssss.................................. [ 79%]
....ssssssssssssss............ssssssssssssss............ssssssssssssss............ssssssssssssss.......sss                           [ 84%]
pyfakefs/tests/fake_pathlib_test.py ....s.sssssssssssssss.s......sssssssss.s..........s....sssssssssssssssss...ss........s.......... [ 89%]
.sssssssssssssssssssssssssss.......................................s...sssssssssssssssssssssssssssssssssssssssssss.....              [ 95%]
pyfakefs/tests/fake_stat_time_test.py .......sssssss........ssssssss.......sssssss........ssssssss.....sssss......ssssss             [ 99%]
pyfakefs/tests/fake_tempfile_test.py ........                                                                                        [ 99%]
pyfakefs/tests/mox3_stubout_test.py .........                                                                                        [100%]

=============================================== 1239 passed, 825 skipped, 4 xfailed in 5.70s ===============================================
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/home/sophie/.local/dev/pyfakefs/pyfakefs/fake_filesystem.py", line 2210, in get_object_from_normpath
    target = target.get_entry(component)  # type: ignore
  File "/home/sophie/.local/dev/pyfakefs/pyfakefs/fake_filesystem.py", line 733, in get_entry
    return self.entries[to_string(pathname_name)]
KeyError: 'pytest-of-sophie'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sophie/.local/lib/python3.8/site-packages/_pytest/pathlib.py", line 342, in cleanup_numbered_dir
    for path in cleanup_candidates(root, prefix, keep):
  File "/home/sophie/.local/lib/python3.8/site-packages/_pytest/pathlib.py", line 328, in cleanup_candidates
    max_existing = max(map(parse_num, find_suffixes(root, prefix)), default=-1)
  File "/home/sophie/.local/lib/python3.8/site-packages/_pytest/pathlib.py", line 170, in extract_suffixes
    for p in iter:
  File "/home/sophie/.local/lib/python3.8/site-packages/_pytest/pathlib.py", line 158, in find_prefixed
    for x in root.iterdir():
  File "/usr/lib/python3.8/pathlib.py", line 1122, in iterdir
    for name in self._accessor.listdir(self):
  File "/home/sophie/.local/dev/pyfakefs/pyfakefs/fake_pathlib.py", line 62, in _wrapped
    return strfunc(pathobj.filesystem, str(pathobj), *args, **kwargs)
  File "/home/sophie/.local/dev/pyfakefs/pyfakefs/fake_filesystem.py", line 3382, in listdir
    directory = self.confirmdir(target_directory)
  File "/home/sophie/.local/dev/pyfakefs/pyfakefs/fake_filesystem.py", line 3288, in confirmdir
    directory = cast(FakeDirectory, self.resolve(target_directory))
  File "/home/sophie/.local/dev/pyfakefs/pyfakefs/fake_filesystem.py", line 2265, in resolve
    return self.get_object_from_normpath(self.resolve_path(
  File "/home/sophie/.local/dev/pyfakefs/pyfakefs/fake_filesystem.py", line 2215, in get_object_from_normpath
    self.raise_os_error(errno.ENOENT, path)
  File "/home/sophie/.local/dev/pyfakefs/pyfakefs/fake_filesystem.py", line 1098, in raise_os_error
    raise OSError(err_no, message, filename)
FileNotFoundError: [Errno 2] No such file or directory in the fake filesystem: '/tmp/pytest-of-sophie'

@mrbean-bremen
Copy link
Member

Ok, thank you - the same has been reported by another user, and I'm not sure yet was causes this (though I have an idea where this comes from). I won't have more time today to investigate this, will have another look tomorrow evening. I have made a patch release with the current version (mainly because of the Python 3.11 fix), and if I can fix this, I can probably make another one. Thanks for your fast responses - I much appreciate this kind of fast feedback!

@mrbean-bremen mrbean-bremen reopened this Jul 13, 2022
@nicolashainaux
Copy link
Author

Thank you for your quick answers too!
I'll answer as quick as possible. Sometimes it can't be as quick as I wish (tonight I'm not sure, maybe it'll be late).

github-actions bot pushed a commit that referenced this issue Jul 14, 2022
… cause such errors with some combinations of tests - should fix #687
@mrbean-bremen
Copy link
Member

mrbean-bremen commented Jul 14, 2022

I removed the offending test, will reopen the respective issue to handle this. The error should be gone now - I will publish a new patch release soon. Edit: done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants