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

Four tests fails without HOME #870

Closed
mtelka opened this issue Aug 23, 2023 · 4 comments · Fixed by #871
Closed

Four tests fails without HOME #870

mtelka opened this issue Aug 23, 2023 · 4 comments · Fixed by #871

Comments

@mtelka
Copy link

mtelka commented Aug 23, 2023

Describe the bug

The following four tests fails without the HOME environment variable:

=========================== short test summary info ============================
FAILED pyfakefs/tests/fake_filesystem_test.py::FakePathModuleTest::test_expand_user
FAILED pyfakefs/tests/fake_filesystem_unittest_test.py::TestOtherFS::test_real_file_with_home
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_expanduser
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_home
=========== 4 failed, 1281 passed, 858 skipped, 4 xfailed in 17.86s ============

The log for three failures is like this:

_____________________ FakePathModuleTest.test_expand_user ______________________

self = <pyfakefs.tests.fake_filesystem_test.FakePathModuleTest testMethod=test_expand_user>

    def test_expand_user(self):
        if self.is_windows:
            self.assertEqual(
                self.path.expanduser("~"),
                self.os.environ["USERPROFILE"].replace("\\", "!"),
            )
        else:
            self.assertEqual(
                self.path.expanduser("~"),
>               self.os.environ["HOME"].replace("/", "!"),
            )

pyfakefs/tests/fake_filesystem_test.py:1073:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = environ({'LC_CTYPE': 'C.UTF-8', 'PYTHONPATH': '...stripped...', 'PYTEST_CURRENT_TEST': 'pyfakefs/tests/fake_filesystem_test.py::FakePathModuleTest::test_expand_user (call)'})
key = 'HOME'

    def __getitem__(self, key):
        try:
            value = self._data[self.encodekey(key)]
        except KeyError:
            # raise KeyError with the original key value
>           raise KeyError(key) from None
E           KeyError: 'HOME'

/usr/lib/python3.9/os.py:679: KeyError

The fourth test (TestOtherFS.test_real_file_with_home) fails with different error message, but the failure is caused by missing HOME too.

How To Reproduce

Run tests without the HOME variable set, for example via env -.

Your environment
Please run the following in the environment where the problem happened and
paste the output.

$ python -c "import platform; print(platform.platform())"
SunOS-5.11-i86pc-i386-64bit-ELF
$ python -c "import sys; print('Python', sys.version)"
Python 3.9.16 (main, Feb 19 2023, 15:42:40) 
[GCC 10.4.0]
$ python -c "from pyfakefs import __version__; print('pyfakefs', __version__)"
pyfakefs 5.2.4
$ python -c "import pytest; print('pytest', pytest.__version__)"
pytest 7.4.0
$
@mtelka
Copy link
Author

mtelka commented Aug 23, 2023

I think this is regression from 5.2.3.

@mrbean-bremen
Copy link
Member

Thanks, I will have a look!

@mrbean-bremen
Copy link
Member

Ok, this is not a regression (the code has been there since 2016), just an issue of the test environment.
Has to be fixed in the tests.

@mtelka
Copy link
Author

mtelka commented Aug 23, 2023

You are right. I just tried to run tests for 5.2.3 and they failed similarly. I noticed that when tests are run with the pytest-checkdocs plugin installed then all of them pass. Apparently, previously (the 5.2.3 version) I tested with the plugin installed and today (5.2.4) I tested with checkdocs uninstalled so it looked to me like a regression.

Thank you.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Aug 23, 2023
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Aug 23, 2023
mrbean-bremen added a commit that referenced this issue Aug 24, 2023
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

Successfully merging a pull request may close this issue.

2 participants