In a python test function
def test_something(tmpdir):
with tmpdir.as_cwd() as p:
print('here', p)
print(os.getcwd())
I was expecting p and the os.getcwd() would give the same result. But in reality, p points to the directory of the test file whereas os.getcwd() points to the expected temporary file.
Is this expected behavior?
Take a look at the docs of
py.path.as_cwd:The behaviour you are observing is thus correct:
Just remember that
pin your example is not the "new" current dir you are changing to, it's the "old" one you changed from.