Skip to content

python 3.9.18 + pyfakefs + pathlib + class variable: test failed #935

Description

@khiker

Describe the bug
following test failed under python 3.9.18. but 3.12.1 success.

import pathlib
class ClassVariable():
    PATH = pathlib.Path("/tmp/foobar.txt")
    def __init__(self):
        pass
    def exists(self):
        return ClassVariable.PATH.is_file()

import pytest
def test_classvariable(fs):
    fs.create_file(ClassVariable.PATH)
    assert ClassVariable().exists() == True

How To Reproduce
run above script.

Result (3.9.18):

$ pytest -v ./test.py
============================================================================================== test session starts ==============================================================================================
platform linux -- Python 3.9.18, pytest-7.4.4, pluggy-1.3.0 -- /home/kiyoto/.anyenv/envs/pyenv/versions/3.9.18/bin/python3.9
cachedir: .pytest_cache
rootdir: /tmp/yyy
plugins: pyfakefs-5.3.4
collected 1 item

test.py::test_classvariable FAILED                                                                                                                                                                        [100%]

=================================================================================================== FAILURES ====================================================================================================
______________________________________________________________________________________________ test_classvariable _______________________________________________________________________________________________

fs = <pyfakefs.fake_filesystem.FakeFilesystem object at 0x7fa88069bbe0>

    def test_classvariable(fs):
        fs.create_file(ClassVariable.PATH)
>       assert ClassVariable().exists() == True
E       assert False == True
E        +  where False = <bound method ClassVariable.exists of <test.ClassVariable object at 0x7fa88070a400>>()
E        +    where <bound method ClassVariable.exists of <test.ClassVariable object at 0x7fa88070a400>> = <test.ClassVariable object at 0x7fa88070a400>.exists
E        +      where <test.ClassVariable object at 0x7fa88070a400> = ClassVariable()

/tmp/yyy/test.py:12: AssertionError

Result (3.12.1)

$ poetry run pytest -vvv test.py
============================================================================================== test session starts ==============================================================================================
platform linux -- Python 3.12.1, pytest-7.4.4, pluggy-1.3.0 -- /home/kiyoto/.cache/pypoetry/virtualenvs/xxx-76ftnvza-py3.12/bin/python
cachedir: .pytest_cache
rootdir: /tmp/xxx
plugins: pyfakefs-5.3.4
collected 1 item

test.py::test_classvariable PASSED

Your environment

$ python -c "import platform; print(platform.platform())"
Linux-6.6.11-amd64-x86_64-with-glibc2.37
$ python -c "import sys; print('Python', sys.version)"
Python 3.9.18 (main, Jan 20 2024, 10:42:53)
[GCC 13.2.0]
$ python -c "from pyfakefs import __version__; print('pyfakefs', __version__)"
pyfakefs 5.3.4
$ python -c "import pytest; print('pytest', pytest.__version__)"
pytest 7.4.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions