import pytest @pytest.yield_fixture def tmpdir_cwd(tmpdir): with tmpdir.as_cwd() as orig: yield orig