ÿØÿà JFIF ` ` ÿþxØ
| Server IP : 109.234.164.53 / Your IP : 216.73.216.136 Web Server : Apache System : Linux cervelle.o2switch.net 4.18.0-553.32.1.lve.el8.x86_64 #1 SMP Thu Dec 19 13:14:03 UTC 2024 x86_64 User : computer3 ( 1098) PHP Version : 7.1.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /opt/alt/python37/lib/python3.7/site-packages/pyfakefs/ |
Upload File : |
"""A pytest plugin for using pyfakefs as a fixture
When pyfakefs is installed, the "fs" fixture becomes available.
:Usage:
def my_fakefs_test(fs):
fs.create_file('/var/data/xx1.txt')
assert os.path.exists('/var/data/xx1.txt')
"""
import linecache
import tokenize
import py
import pytest
from pyfakefs.fake_filesystem_unittest import Patcher
Patcher.SKIPMODULES.add(pytest)
Patcher.SKIPMODULES.add(py) # Ignore pytest components when faking filesystem
# The "linecache" module is used to read the test file in case of test failure
# to get traceback information before test tear down.
# In order to make sure that reading the test file is not faked,
# we both skip faking the module, and add the build-in open() function
# as a local function in the module (used in Python 2).
# In Python 3, we also have to set back the cached open function in tokenize.
Patcher.SKIPMODULES.add(linecache)
Patcher.SKIPMODULES.add(tokenize)
@pytest.fixture
def fs():
""" Fake filesystem. """
patcher = Patcher()
patcher.setUp()
linecache.open = patcher.original_open
tokenize._builtin_open = patcher.original_open
yield patcher.fs
patcher.tearDown()