MCPcopy
hub / github.com/pytest-dev/pytest / as_cwd

Method as_cwd

src/_pytest/_py/path.py:1005–1016  ·  view source on GitHub ↗

Return a context manager, which changes to the path's dir during the managed "with" context. On __enter__ it returns the old dir, which might be ``None``.

(self)

Source from the content-addressed store, hash-verified

1003
1004 @contextmanager
1005 def as_cwd(self):
1006 """
1007 Return a context manager, which changes to the path's dir during the
1008 managed "with" context.
1009 On __enter__ it returns the old dir, which might be ``None``.
1010 """
1011 old = self.chdir()
1012 try:
1013 yield old
1014 finally:
1015 if old is not None:
1016 old.chdir()
1017
1018 def realpath(self):
1019 """Return a new path which contains no symbolic links."""

Callers 7

test_chdir_goneMethod · 0.80
test_as_cwdMethod · 0.80
test_as_cwd_exceptionMethod · 0.80
test_samefileFunction · 0.80

Calls 1

chdirMethod · 0.95

Tested by 7

test_chdir_goneMethod · 0.64
test_as_cwdMethod · 0.64
test_as_cwd_exceptionMethod · 0.64
test_samefileFunction · 0.64