Skip to content

Replacing tmp_path with FakePath #1147

Answered by mrbean-bremen
jfindlay asked this question in Q&A
Discussion options

You must be logged in to vote

While it is possible to instantiate and use the fake fs classes directly (this was the original use case at Google when the library was first written, and partly still is today), you shouldn't need to do this if you use pytest with the fs fixture, unittest with fake_filesystem_unittest.TestCase, or fake_filesystem_unittest.Patcher directly. In these cases, it is sufficient to use just the standard filesystem functions, and, if wanted, some of the convenience functions.

Your specific use case (replacement of tmp_path) can be achieved by just using tempfile:

@pytest.fixture
def temp_path(fs):
    tmp_dir = tempfile.TemporaryDirectory()
    yield Path(tmp_dir.name)

This would return a newly …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jfindlay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants