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

pathlib.Path(".").absolute() uses an unmocked os module #527

Closed
tnek213 opened this issue Mar 30, 2020 · 3 comments
Closed

pathlib.Path(".").absolute() uses an unmocked os module #527

tnek213 opened this issue Mar 30, 2020 · 3 comments
Labels

Comments

@tnek213
Copy link

tnek213 commented Mar 30, 2020

Description
pathlib.Path(".").absolute() uses an unmocked os module and I can't find a way to reload it.

How To Reproduce

from pyfakefs.fake_filesystem_unittest import TestCase

import os
import pathlib


class Test(TestCase):
    def setUp(self):
        self.setUpPyfakefs()
        os.chdir("/")

    def test_cwd(self):
        print("cwd: %s" % os.getcwd())
        dot_abs = pathlib.Path(".").absolute()
        print("dot abs: %s" % dot_abs)
        print("exists dot abs: %s" % dot_abs.exists())

Prints the following when running test_cwd

cwd: /
dot abs: /home/k/PycharmProjects/mytestproj/tests
exists dot abs: False

While I expected:

cwd: /
dot abs: /
exists dot abs: True

As can be seen the file system is mocked, but os.getcwd() used by the absolute() function of Path isn't and returns the real cwd.

Enviroment

Linux-4.18.0-25-generic-x86_64-with-Ubuntu-18.10-cosmic
Python 3.6.8 (default, Apr  9 2019, 04:59:38) 
pyfakefs 4.0.2
@mrbean-bremen
Copy link
Member

Thanks - I will have a look.

@mrbean-bremen
Copy link
Member

@tnek213 - Thanks for catching this - I'm amazed that this came up only now!

@tnek213
Copy link
Author

tnek213 commented Mar 31, 2020

@mrbean-bremen Thank you! Both for the lib which seems awesome and the amazing response time!

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

No branches or pull requests

2 participants