-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pytest 5.4.0 breaks tests #93
Comments
Thanks for reporting. I've setup a nightly build and it passed this morning with pytest 5.4.0. But, that's |
Alrighty, I see it over in the Scrapy build on Travis. And of course I was quickly just running pytest-twisted tests. I'll let you know what I can figure out. |
I'm looking but have you done any debugging on this? So far it looks like scrapy code is managing the subprocessing by way of FetchTest inheriting from ProcessTest? It also looks to be an issue in the the first test within the class and be that the process is attempting to be reaped before it has even been forked? |
This comment has been minimized.
This comment has been minimized.
got it running with pytest directly, my bad |
From what I can tell it happens in the first run test of def execute(self, args, check_code=True, settings=None):
env = os.environ.copy()
if settings is not None:
env['SCRAPY_SETTINGS_MODULE'] = settings
cmd = self.prefix + [self.command] + list(args)
pp = TestProcessProtocol()
pp.deferred.addBoth(self._process_finished, cmd, check_code)
reactor.spawnProcess(pp, cmd[0], cmd, env=env, path=self.cwd)
return pp.deferred Git bisect points at pytest-dev/pytest@04f27d4. git bisect run bash -c 'cd ../scrapy; venv/bin/pytest tests/test_command_fetch.py' @blueyed, maybe you have some quick insight to share? If not, we can keep digging. I will note that there's a pretty significant rework over in #91 changing how pytest-twisted uses the pytest plugin hooks (significant relative to the fairly small pytest-twisted, that is). Sadly that didn't seem to change anything. So I think we can call
And if you further avoid calling And yes... I see that this has nothing to do with pytest or pytest-twisted. I expect the potential further indicated issue may lead back to one of them (or scrapy itself perhaps). |
Running those tests with |
So my present analysis is that... pytest changed something (haven't gotten to analyzing that) that now exposes that scrapy calls a deferred's I still plan to try to figure out from the Twisted side if this is in error in how the pid gets set to scrapy/scrapy#4426 is an exploratory PR in case Twisted decides that the answer is to not allow |
@altendky |
Avoid log failure when reaping of None PID is requested
(not a solution, just a thing to be fixed) @blueyed, thanks. I'll read up on that when I get back to the core issue. Got another Twisted PR to fit in etc... |
t.i.process._BaseProcess.reapProcess() sets self.pid to None before unregistering
So... I'm not sure this should be called a fix but it does seem to alleviate the symptom. @Gallaecio, could you give this a try at some point? The thing I don't like is not being sure why the scrapy test end up back in the reactor where it tries to reap all the processes while still in the middle of reaping the one being tested. |
I will try to give it a try this week. |
Alrighty, so at least there's a test in pytest-twisted itself that shows the same issue... twisted/twisted#1240 'fixes' it. Though I think i want to test more specifically about the 're-entering' into the reactor. Fun, with the asyncio reactor you get |
Alrighty, so since https://github.com/pytest-dev/pytest-twisted/pull/94/checks?check_run_id=546309854 test_scrapy____something.py::Test::test FAILED [100%]
test_scrapy____something.py::Test::test ERROR [100%]
==================================== ERRORS ====================================
________________________ ERROR at teardown of Test.test ________________________
self = <test_scrapy____something.Test testMethod=test>
result = <TestCaseFunction test>
def _classCleanUp(self, result):
try:
> util._Janitor(self, result).postClassCleanup()
/home/runner/work/pytest-twisted/pytest-twisted/.tox/py38-asyncioreactor/lib/python3.8/site-packages/twisted/trial/_asynctest.py:226:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/runner/work/pytest-twisted/pytest-twisted/.tox/py38-asyncioreactor/lib/python3.8/site-packages/twisted/trial/util.py:113: in postClassCleanup
calls = self._cleanPending()
/home/runner/work/pytest-twisted/pytest-twisted/.tox/py38-asyncioreactor/lib/python3.8/site-packages/twisted/internet/utils.py:238: in warningSuppressingWrapper
return runWithWarningsSuppressed(suppressedWarnings, f, *a, **kw)
/home/runner/work/pytest-twisted/pytest-twisted/.tox/py38-asyncioreactor/lib/python3.8/site-packages/twisted/internet/utils.py:221: in runWithWarningsSuppressed
reraise(exc_info[1], exc_info[2])
/home/runner/work/pytest-twisted/pytest-twisted/.tox/py38-asyncioreactor/lib/python3.8/site-packages/twisted/python/compat.py:464: in reraise
raise exception.with_traceback(traceback)
/home/runner/work/pytest-twisted/pytest-twisted/.tox/py38-asyncioreactor/lib/python3.8/site-packages/twisted/internet/utils.py:217: in runWithWarningsSuppressed
result = f(*a, **kw)
/home/runner/work/pytest-twisted/pytest-twisted/.tox/py38-asyncioreactor/lib/python3.8/site-packages/twisted/trial/util.py:138: in _cleanPending
reactor.iterate(0)
/home/runner/work/pytest-twisted/pytest-twisted/.tox/py38-asyncioreactor/lib/python3.8/site-packages/twisted/trial/_asynctest.py:242: in _
return self._reactorMethods[name](*a, **kw)
/home/runner/work/pytest-twisted/pytest-twisted/.tox/py38-asyncioreactor/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py:262: in iterate
self._asyncioEventloop.run_forever()
/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/asyncio/base_events.py:560: in run_forever
self._check_running()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_UnixSelectorEventLoop running=False closed=False debug=False>
def _check_running(self):
if self.is_running():
> raise RuntimeError('This event loop is already running')
E RuntimeError: This event loop is already running
/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/asyncio/base_events.py:552: RuntimeError |
@altendky |
@blueyed, thanks for poking me on this. It sounds like you are confident this is just a pytest bug. Would you expect the (indirectly) linked blueyed/pytest#107 to fix it? It doesn't seem to. If you think I shouldn't bother, I'll stop and wait and see what happens with pytest. If you think I might dig up some useful info... I might find some more time for this. Thanks for looking out for me, just like everyone else I've certainly got other open issues to be working on. |
blueyed/pytest#107 was just an attempt to refactor it to make it work, nothing finished. |
The two related Twisted issues have been completed and are available in trunk. This may be sufficient to alleviate the symptoms in the scrapy tests. At present I don't plan to dig into this a lot more right now. Not because I think these Twisted changes count as a fix but rather because of the encouragement to let pytest fix it. I've got a few other open source activities I'm trying to get work done on too. |
@Gallaecio, per the test I added in #94 it seems that pytest==5.4.2 may have fixed this. Checking in scrapy/scrapy#4588. |
It looks like pytest-dev/pytest#7156 may be the fix (if i did my backwards bisect correctly). @Gallaecio, does it seem fixed to you also? (PR passed) |
It seems to happen in the cleanup stage after all the tests of a TestCase, and marks the last test of that TestCase as a failure.
The text was updated successfully, but these errors were encountered: