Skip to content
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

Slave 'gw0' crashed when using pytest.exit() #86

Closed
rosariomgomez opened this issue Aug 29, 2016 · 11 comments
Closed

Slave 'gw0' crashed when using pytest.exit() #86

rosariomgomez opened this issue Aug 29, 2016 · 11 comments
Labels

Comments

@rosariomgomez
Copy link

Environment:
python 3.5.2
pytest==2.9.2
pytest-xdist==1.15.0
pytest-randomly==1.0.0

When using the method pytest.exit(msg) to immediately exit the test run, I've got the following error (for any value of n):
Slave 'gw0' crashed while running 'test_name' !!!!! xdist.dsession.Interrupted: <SlaveController gw0> received keyboard-interrupt !!!!

Am I missing any other parameter (besides -n) that I should be passing?

Thanks for your help! Please, let me know if there is any extra information I can provide that could help to debug the issue.

@nicoddemus nicoddemus added the bug label Aug 29, 2016
@nicoddemus
Copy link
Member

Thanks for the report.

That seems like a bug in xdist, it should handle the pytest.Exit exception correctly.

@Daenyth
Copy link

Daenyth commented Sep 14, 2016

This is is fairly painful for me, as I use xdist on our CI for integration tests - failed setup (errors in migration, etc) aborts the pytest run but the errors don't get reported nicely to the dev.

If there's some clear guidance on how to approach this I might be able to put in a PR

@nicoddemus
Copy link
Member

@Daenyth are they aborted by pytest.Exit or some other error?

@Daenyth
Copy link

Daenyth commented Sep 14, 2016

I invoke pytest.exit(failmsg)

When I omit the -n parameter I get back the message on the summary line

@nicoddemus
Copy link
Member

Thanks, I was asking just to know for sure if it was crashing due to something else.

@Daenyth
Copy link

Daenyth commented Sep 27, 2016

@nicoddemus Do you think this is a reasonably easy fix to contribute? I think a test case shouldn't be too hard to create showing the issue.

@nicoddemus
Copy link
Member

A PR with an xfail test would be very welcome!

@feuillemorte
Copy link
Contributor

It's difficult to fix this issue because pytest sends {'exitstatus': 2} to xdist and xdist think that it is keyboard-interrupt:

pytest (main.py)

        except KeyboardInterrupt:
            excinfo = _pytest._code.ExceptionInfo()
            if initstate < 2 and isinstance(excinfo.value, exit.Exception):
                sys.stderr.write('{0}: {1}\n'.format(
                    excinfo.typename, excinfo.value.msg))
            config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
            session.exitstatus = EXIT_INTERRUPTED

xdist (dsession.py):

    def slave_slavefinished(self, node):
        """Emitted when node executes its pytest_sessionfinish hook.

        Removes the node from the scheduler.

        The node might not be in the scheduler if it had not emitted
        slaveready before shutdown was triggered.
        """
        self.config.hook.pytest_testnodedown(node=node, error=None)
        if node.slaveoutput['exitstatus'] == 2:  # keyboard-interrupt
            self.shouldstop = "%s received keyboard-interrupt" % (node,)
            self.slave_errordown(node, "keyboard-interrupt")
            return
        if node in self.sched.nodes:
            crashitem = self.sched.remove_node(node)
            assert not crashitem, (crashitem, node)
        self._active_nodes.remove(node)

Maybe we can except smth like except Exit: session.exitstatus = ANOTHER_STATUS, but this code didn't worked for me

So, if smb knows how to fix it easy please, give me an advice)

@nicoddemus
Copy link
Member

@feuillemorte good point, I see that Exit is a subclass of KeyboardInterrupt, which seems weird at first glance. Regardless, we should catch and treat Exit differently in _pytest.main.py to gracefully exit stating that it was caused by an explicit pytest.exit() call.

@feuillemorte
Copy link
Contributor

feuillemorte commented Jan 23, 2018

I'll create a task to pytest (which branch? master?) but I really don't know how to pass message to xdist module from pytest:

https://github.com/pytest-dev/pytest/blob/0d96a5bf9059e51324ac24ec24d68af1c35db6d8/_pytest/main.py#L110-L116

@pytest.hookimpl(hookwrapper=True)
def pytest_sessionfinish(self, exitstatus):
self.config.slaveoutput['exitstatus'] = exitstatus
yield
self.sendevent("slavefinished", slaveoutput=self.config.slaveoutput)

task:
pytest-dev/pytest#3144

@blueyed
Copy link
Contributor

blueyed commented Nov 21, 2019

Might have changed/improved in pytest: pytest-dev/pytest#3144 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants