You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not sure if this is actually an issue or it is something that I do not understand. So I have a module that makes use of tempfile to create temporary directory and manipulate files in the directory. When I test with out pyfakefs, things are OK and tests are OK as well. But I when I load pyfakefs in another test file that will be run before this test file, things will break -- temporary dir will not be created, and writing to files in temprorary dir will fail of course.
I am using Python 3.6.1. Ubuntu 16.04.
A minimal case:
And the output:
(.venv36) jgu@jgu-pc:~/repos/temp % py.test -vv -s tests/test_abc.py
=========================================================================================== test session starts ============================================================================================
platform linux -- Python 3.6.1, pytest-3.4.2, py-1.5.2, pluggy-0.6.0 -- /home/jgu/repos/.venv36/bin/python3.6
cachedir: .pytest_cache
rootdir: /home/jgu/repos/temp, inifile:
plugins: mock-1.7.1, cov-2.5.1, pyfakefs-3.4
collected 1 item
tests/test_abc.py::test_func PASSED
========================================================================================= 1 passed in 0.11 seconds =========================================================================================
(.venv36) jgu@jgu-pc:~/repos/temp % py.test -vv -s
=========================================================================================== test session starts ============================================================================================
platform linux -- Python 3.6.1, pytest-3.4.2, py-1.5.2, pluggy-0.6.0 -- /home/jgu/repos/.venv36/bin/python3.6
cachedir: .pytest_cache
rootdir: /home/jgu/repos/temp, inifile:
plugins: mock-1.7.1, cov-2.5.1, pyfakefs-3.4
collected 2 items
tests/test_a.py::test_void PASSED
tests/test_abc.py::test_func FAILED
================================================================================================= FAILURES =================================================================================================
________________________________________________________________________________________________ test_func _________________________________________________________________________________________________
def func():
try:
td = tempfile.TemporaryDirectory()
> with open(td.name + '/tmp.txt', 'w') as ofile:
E FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpoepn6_lx/tmp.txt'
packa/abc.py:7: FileNotFoundError
During handling of the above exception, another exception occurred:
def test_func():
> assert abc.func()
tests/test_abc.py:5:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
packa/abc.py:11: in func
td.cleanup()
../.venv36/lib/python3.6/tempfile.py:811: in cleanup
_shutil.rmtree(self.name)
../.venv36/lib/python3.6/shutil.py:471: in rmtree
onerror(os.lstat, path, sys.exc_info())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
path = '/tmp/tmpoepn6_lx', ignore_errors = False, onerror = <function rmtree.<locals>.onerror at 0x7f221a845bf8>
def rmtree(path, ignore_errors=False, onerror=None):
"""Recursively delete a directory tree.
If ignore_errors is set, errors are ignored; otherwise, if onerror
is set, it is called to handle the error with arguments (func,
path, exc_info) where func is platform and implementation dependent;
path is the argument to that function that caused it to fail; and
exc_info is a tuple returned by sys.exc_info(). If ignore_errors
is false and onerror is None, an exception is raised.
"""
if ignore_errors:
def onerror(*args):
pass
elif onerror is None:
def onerror(*args):
raise
if _use_fd_functions:
# While the unsafe rmtree works fine on bytes, the fd based does not.
if isinstance(path, bytes):
path = os.fsdecode(path)
# Note: To guard against symlink races, we use the standard
# lstat()/open()/fstat() trick.
try:
> orig_st = os.lstat(path)
E FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpoepn6_lx'
../.venv36/lib/python3.6/shutil.py:469: FileNotFoundError
==================================================================================== 1 failed, 1 passed in 0.19 seconds ====================================================================================
The text was updated successfully, but these errors were encountered:
I am not sure if this is actually an issue or it is something that I do not understand. So I have a module that makes use of tempfile to create temporary directory and manipulate files in the directory. When I test with out pyfakefs, things are OK and tests are OK as well. But I when I load pyfakefs in another test file that will be run before this test file, things will break -- temporary dir will not be created, and writing to files in temprorary dir will fail of course.
I am using Python 3.6.1. Ubuntu 16.04.
A minimal case:
And the output:
The text was updated successfully, but these errors were encountered: