I/O operation on closed file
smarlowucf opened this issue · comments
pytest: 3.10.1
py: 1.8.1
pluggy: 0.13.1
I'm sporadically seeing an I/O error when running tests from code:
File "/usr/lib/python3.6/site-packages/img_proof/ipa_cloud.py", line 367, in _run_test
result = pytest.main(cmds, plugins=[plugin])
File "/usr/lib/python3.6/site-packages/_pytest/config/__init__.py", line 78, in main
return config.hook.pytest_cmdline_main(config=config)
File "/usr/lib/python3.6/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 87, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
return outcome.get_result()
File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/usr/lib/python3.6/site-packages/_pytest/main.py", line 217, in pytest_cmdline_main
return wrap_session(config, _main)
File "/usr/lib/python3.6/site-packages/_pytest/main.py", line 210, in wrap_session
session=session, exitstatus=session.exitstatus
File "/usr/lib/python3.6/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 87, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 203, in _multicall
gen.send(outcome)
File "/usr/lib/python3.6/site-packages/_pytest/terminal.py", line 631, in pytest_sessionfinish
self._tw.line("")
File "/usr/lib/python3.6/site-packages/py/_io/terminalwriter.py", line 273, in line
self.write('\n')
File "/usr/lib/python3.6/site-packages/py/_io/terminalwriter.py", line 256, in write
write_out(self._file, markupmsg)
File "/usr/lib/python3.6/site-packages/py/_io/terminalwriter.py", line 406, in write_out
fil.write(msg)
ValueError: I/O operation on closed file.
Because this is happening intermittently I am struggling to pinpoint what the issue is. Any ideas on how to resolve this? Possibly an issue with package versions?
As a note, I was previously running with the following package versions and didn't see this same problem:
pytest: 3.10.1
py: 1.5.2
pluggy: 0.7.1
Closing for now. I think I narrowed down the issue here. I was redirecting stdout to a file before invoking pytest and I think that was causing issues when pytest also hijacked the stdout buffer. For now I am testing by disabling the pytest capture entirely with the -s
option as seen in docs https://docs.pytest.org/en/stable/capture.html.