-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix documentation for cleanup handlers
- add convenience handler 'reload_cleanup_handler'
- Loading branch information
1 parent
3852d0f
commit 07bd3f7
Showing
6 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import pathlib | ||
|
||
|
||
def use_pathlib(path: str): | ||
return pathlib.Path(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def load(path: str) -> str: | ||
from pyfakefs.pytest_tests import lib_using_pathlib | ||
|
||
return lib_using_pathlib.use_pathlib(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
|
||
from pyfakefs.fake_filesystem_unittest import Patcher | ||
from pyfakefs.fake_pathlib import FakePathlibModule | ||
from pyfakefs.helpers import reload_cleanup_handler | ||
from pyfakefs.pytest_tests import local_import | ||
|
||
|
||
@pytest.fixture | ||
def test_fs(): | ||
with Patcher() as patcher: | ||
patcher.cleanup_handlers["pyfakefs.pytest_tests.lib_using_pathlib"] = ( | ||
reload_cleanup_handler | ||
) | ||
yield patcher.fs | ||
|
||
|
||
class TestReloadCleanupHandler: | ||
def test1(self, test_fs): | ||
path = local_import.load("some_path") | ||
assert isinstance(path, FakePathlibModule.Path) | ||
|
||
def test2(self): | ||
path = local_import.load("some_path") | ||
# will fail without reload handler | ||
assert not isinstance(path, FakePathlibModule.Path) |