Поддельный pathlib.Path в переменной класса с использованием pyfakefs' ⇐ Python
Поддельный pathlib.Path в переменной класса с использованием pyfakefs'
I have a class variable of type pathlib.Path.
from pathlib import Path class MyClass: FILE_PATH = Path('/etc/ids.json') I know that pyfakefs is not able to mock this automatically. So in my test I use its Patcher class (I also tried other ways.) to reload the corresponding module.
from pathlib import Path from pyfakefs.fake_filesystem_unittest import Patcher from pyfakefs.fake_pathlib import FakePathlibModule from . import my_class def test_class_variable(fs): # my_class.MyClass.FILE_PATH = Path('/etc/ids.json') with Patcher(modules_to_reload=[my_class]): assert type(my_class.MyClass.FILE_PATH) is FakePathlibModule.PosixPath But it still isn't mocked.
If I uncomment the commented line, the test succeeds.
What should I do to mock the class variable?
Источник: https://stackoverflow.com/questions/781 ... g-pyfakefs
I have a class variable of type pathlib.Path.
from pathlib import Path class MyClass: FILE_PATH = Path('/etc/ids.json') I know that pyfakefs is not able to mock this automatically. So in my test I use its Patcher class (I also tried other ways.) to reload the corresponding module.
from pathlib import Path from pyfakefs.fake_filesystem_unittest import Patcher from pyfakefs.fake_pathlib import FakePathlibModule from . import my_class def test_class_variable(fs): # my_class.MyClass.FILE_PATH = Path('/etc/ids.json') with Patcher(modules_to_reload=[my_class]): assert type(my_class.MyClass.FILE_PATH) is FakePathlibModule.PosixPath But it still isn't mocked.
If I uncomment the commented line, the test succeeds.
What should I do to mock the class variable?
Источник: https://stackoverflow.com/questions/781 ... g-pyfakefs
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение