-
Notifications
You must be signed in to change notification settings - Fork 94
Description
I'm using pyfakefs with some test cases that involve spinning up subprocesses, but unfortunately, the subprocess library doesn't appear to be supported yet, because of path resolution for the executables.
This may be harder than it looks, but on a cursory glance it seems that the only hangup is that os.path functions like split and join support both bytes and str to be passed as arguments, and return the corresponding type. The subprocess library internally calls os functions with bytes arguments, but this causes a TypeError because os.path.split() and the like in pyfakefs only support strings.
Here's a minimal example:
import subprocess
from pyfakefs import fake_filesystem_unittest
class TestSubprocess(fake_filesystem_unittest.TestCase):
def setUp(self):
self.setUpPyfakefs()
self.copyRealFile("/bin/nc", "/bin/nc")
def test_run_nc(self):
subprocess.call("/bin/nc") # throws TypeErrorRunning this throws:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/subprocess.py", line 1245, in _execute_child
if os.path.dirname(executable):
File "./env/lib/python3.6/site-packages/pyfakefs/fake_filesystem.py", line 2416, in dirname
return self.split(path)[0]
File "./env/lib/python3.6/site-packages/pyfakefs/fake_filesystem.py", line 2314, in split
return self.filesystem.SplitPath(path)
File "./env/lib/python3.6/site-packages/pyfakefs/fake_filesystem.py", line 970, in SplitPath
path_components = path.split(self.path_separator)
TypeError: a bytes-like object is required, not 'str'
subprocess would be a great additional library to add to the stable of standard libs that work with pyfakefs.