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
An AssertionError is raised at fake_popen.py:188when calling with argument stderr=subprocess.STDOUT if stdout is a file (stdout is expected to be None:
> assert self.stdout is not None
E AssertionError
pyvenv\Lib\site-packages\pytest_subprocess\fake_popen.py:188: AssertionError
subprocess.Popen handles this correctly; stderr is simply written to the file at stdout.
Example
Below is an example demonstrating the error. I have GIT_TRACE set so that git rev-parse gives a small amount of stdout and stderr:
$ git rev-parse HEAD
06:05:28.502294 exec-cmd.c:244 trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
06:05:28.537291 git.c:463 trace: built-in: git rev-parse HEAD
47c77698dd8e0e35af00da56806fe98fcb9a1056
I define a function that runs the subprocess (so that I can call the same thing, using either the fake or real Popen:
defrun_git_revparse():
importosos.environ['GIT_TRACE'] ='1'withNamedTemporaryFile("w+b", delete=False) asf:
path=pathlib.Path(f.name)
# NOTE: I pass f.file because for some reason:# isinstance(f, io.BufferedWriter) == False# so pytest_subprocess isinstance checks would fail. I am# hesitant to change those tests, though you could simply check# for a few key methods:# hasattr(f.mode)# isinstance(f.mode, str)# hasattr(f.write)# isinstance(f.write, types.FunctionType)p=subprocess.Popen(('git', 'rev-parse', 'HEAD'), stdout=f.file, stderr=subprocess.STDOUT)
f.close()
assertp.wait() ==0assertpath.exists()
output=path.read_text()
# print to sys.stdout so I can see with `pytest --capture=no`print('-'*50)
print(output)
print('-'*50)
output=output.splitlines()
assertlen(output) ==3# account for stderr coming before or after stdoutif'exec-cmd.c'inoutput[1]:
output[2], output[0], output[1] =output# first two lines should be stderrassert'exec-cmd.c'inoutput[0]
assert'git.c'inoutput[1]
# last line should be a hex stringassertlen(set(output[2]) -set('0123456789abcdef')) ==0
Then define my test function, which first runs the real git, then the fake "git":
Thank you for reporting that problem. Right now I don't really have time to work on that project. Feel free to submit a PR if you need it sooner, otherwise I'll work on it in the future, but can't specify exactly when.
Description
An
AssertionError
is raised atfake_popen.py
:188when calling with argumentstderr=subprocess.STDOUT
ifstdout
is a file (stdout
is expected to beNone
:subprocess.Popen
handles this correctly; stderr is simply written to the file at stdout.Example
Below is an example demonstrating the error. I have
GIT_TRACE
set so thatgit rev-parse
gives a small amount of stdout and stderr:I define a function that runs the subprocess (so that I can call the same thing, using either the fake or real
Popen
:Then define my test function, which first runs the real
git
, then the fake "git":This raises the assertion error. I can correct this:
Note:
isinstance
testing.io.BufferedRandom
to the group, as that is what I had, and I would expect it should be included...my test still won't work without it.The text was updated successfully, but these errors were encountered: