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

xdist breaks inspect.stack() #340

Closed
pytestbot opened this issue Aug 7, 2013 · 6 comments
Closed

xdist breaks inspect.stack() #340

pytestbot opened this issue Aug 7, 2013 · 6 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Peter Feiner (BitBucket: peterfeiner, GitHub: peterfeiner)


Simple test:

#!sh
peter@gremlin ~/workspace/cobalt [fix-lvm-migrate]
 % cat test.py                       
import inspect
def test():
    inspect.stack()

Works without xidst:

#!sh
peter@gremlin ~/workspace/cobalt [fix-lvm-migrate]
 % py.test --traceconfig test.py
PLUGIN registered: <_pytest.python.FixtureManager instance at 0x23bab48>
===================================== test session starts =====================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
using: pytest-2.3.4 pylib-1.4.15
setuptools registered plugins:
  pytest-xdist-1.8 at /usr/local/lib/python2.7/dist-packages/xdist/plugin.pyc
active plugins:
    helpconfig          : /usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.pyc
    runner              : /usr/local/lib/python2.7/dist-packages/_pytest/runner.pyc
    unittest            : /usr/local/lib/python2.7/dist-packages/_pytest/unittest.pyc
    xdist               : /usr/local/lib/python2.7/dist-packages/xdist/plugin.pyc
    pastebin            : /usr/local/lib/python2.7/dist-packages/_pytest/pastebin.pyc
    skipping            : /usr/local/lib/python2.7/dist-packages/_pytest/skipping.pyc
    genscript           : /usr/local/lib/python2.7/dist-packages/_pytest/genscript.pyc
    session             : <Session 'cobalt'>
    tmpdir              : /usr/local/lib/python2.7/dist-packages/_pytest/tmpdir.pyc
    capture             : /usr/local/lib/python2.7/dist-packages/_pytest/capture.pyc
    terminalreporter    : <_pytest.terminal.TerminalReporter instance at 0x23aea28>
    assertion           : /usr/local/lib/python2.7/dist-packages/_pytest/assertion/__init__.pyc
    mark                : /usr/local/lib/python2.7/dist-packages/_pytest/mark.pyc
    terminal            : /usr/local/lib/python2.7/dist-packages/_pytest/terminal.pyc
    main                : /usr/local/lib/python2.7/dist-packages/_pytest/main.pyc
    config              : /usr/local/lib/python2.7/dist-packages/_pytest/config.pyc
    nose                : /usr/local/lib/python2.7/dist-packages/_pytest/nose.pyc
    python              : /usr/local/lib/python2.7/dist-packages/_pytest/python.pyc
    recwarn             : /usr/local/lib/python2.7/dist-packages/_pytest/recwarn.pyc
    funcmanage          : <_pytest.python.FixtureManager instance at 0x23bab48>
    monkeypatch         : /usr/local/lib/python2.7/dist-packages/_pytest/monkeypatch.pyc
    31763216            : <_pytest.core.PluginManager object at 0x1e4ab10>
    resultlog           : /usr/local/lib/python2.7/dist-packages/_pytest/resultlog.pyc
    capturemanager      : <_pytest.capture.CaptureManager instance at 0x209ae18>
    junitxml            : /usr/local/lib/python2.7/dist-packages/_pytest/junitxml.pyc
    doctest             : /usr/local/lib/python2.7/dist-packages/_pytest/doctest.pyc
    pdb                 : /usr/local/lib/python2.7/dist-packages/_pytest/pdb.pyc
plugins: xdist
collected 1 items 

test.py .

================================== 1 passed in 0.02 seconds ===================================

Running with xdist breaks inspect.stack():

#!sh
peter@gremlin ~/workspace/cobalt [fix-lvm-migrate]
 % py.test -n 1 --traceconfig test.py
PLUGIN registered: <xdist.dsession.TerminalDistReporter instance at 0x24bdf80>
PLUGIN registered: <xdist.dsession.DSession instance at 0x24b2c68>
PLUGIN registered: <_pytest.python.FixtureManager instance at 0x25007a0>
===================================== test session starts =====================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
using: pytest-2.3.4 pylib-1.4.15
setuptools registered plugins:
  pytest-xdist-1.8 at /usr/local/lib/python2.7/dist-packages/xdist/plugin.pyc
active plugins:
    helpconfig          : /usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.pyc
    runner              : /usr/local/lib/python2.7/dist-packages/_pytest/runner.pyc
    unittest            : /usr/local/lib/python2.7/dist-packages/_pytest/unittest.pyc
    xdist               : /usr/local/lib/python2.7/dist-packages/xdist/plugin.pyc
    pastebin            : /usr/local/lib/python2.7/dist-packages/_pytest/pastebin.pyc
    skipping            : /usr/local/lib/python2.7/dist-packages/_pytest/skipping.pyc
    genscript           : /usr/local/lib/python2.7/dist-packages/_pytest/genscript.pyc
    session             : <Session 'cobalt'>
    tmpdir              : /usr/local/lib/python2.7/dist-packages/_pytest/tmpdir.pyc
    capture             : /usr/local/lib/python2.7/dist-packages/_pytest/capture.pyc
    terminalreporter    : <_pytest.terminal.TerminalReporter instance at 0x2487a70>
    assertion           : /usr/local/lib/python2.7/dist-packages/_pytest/assertion/__init__.pyc
    mark                : /usr/local/lib/python2.7/dist-packages/_pytest/mark.pyc
    terminal            : /usr/local/lib/python2.7/dist-packages/_pytest/terminal.pyc
    32652048            : <_pytest.core.PluginManager object at 0x1f23b10>
    terminaldistreporter: <xdist.dsession.TerminalDistReporter instance at 0x24bdf80>
    main                : /usr/local/lib/python2.7/dist-packages/_pytest/main.pyc
    config              : /usr/local/lib/python2.7/dist-packages/_pytest/config.pyc
    nose                : /usr/local/lib/python2.7/dist-packages/_pytest/nose.pyc
    python              : /usr/local/lib/python2.7/dist-packages/_pytest/python.pyc
    recwarn             : /usr/local/lib/python2.7/dist-packages/_pytest/recwarn.pyc
    funcmanage          : <_pytest.python.FixtureManager instance at 0x25007a0>
    monkeypatch         : /usr/local/lib/python2.7/dist-packages/_pytest/monkeypatch.pyc
    resultlog           : /usr/local/lib/python2.7/dist-packages/_pytest/resultlog.pyc
    dsession            : <xdist.dsession.DSession instance at 0x24b2c68>
    capturemanager      : <_pytest.capture.CaptureManager instance at 0x2173e18>
    junitxml            : /usr/local/lib/python2.7/dist-packages/_pytest/junitxml.pyc
    doctest             : /usr/local/lib/python2.7/dist-packages/_pytest/doctest.pyc
    pdb                 : /usr/local/lib/python2.7/dist-packages/_pytest/pdb.pyc
plugins: xdist
gw0 [1]
scheduling tests via LoadScheduling
F
========================================== FAILURES ===========================================
____________________________________________ test _____________________________________________
[gw0] linux2 -- Python 2.7.3 /usr/bin/python
def test():
>       inspect.stack()

test.py:3: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

context = 1

    def stack(context=1):
        """Return a list of records for the stack above the caller's frame."""
>       return getouterframes(sys._getframe(1), context)

/usr/lib/python2.7/inspect.py:1054: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

frame = <frame object at 0x251a290>, context = 1

    def getouterframes(frame, context=1):
        """Get a list of records for a frame and all higher (calling) frames.

        Each record contains a frame object, filename, line number, function
        name, a list of lines of context, and index within the context."""
        framelist = []
        while frame:
>           framelist.append((frame,) + getframeinfo(frame, context))

/usr/lib/python2.7/inspect.py:1032: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

frame = <frame object at 0x251a290>, context = 1

    def getframeinfo(frame, context=1):
        """Get information about a frame or traceback object.

        A tuple of five things is returned: the filename, the line number of
        the current line, the function name, a list of lines of context from
        the source code, and the index of the current line within that list.
        The optional second argument specifies the number of lines of context
        to return, which are centered around the current line."""
        if istraceback(frame):
            lineno = frame.tb_lineno
            frame = frame.tb_frame
        else:
            lineno = frame.f_lineno
        if not isframe(frame):
            raise TypeError('{!r} is not a frame or traceback object'.format(frame))

        filename = getsourcefile(frame) or getfile(frame)
        if context > 0:
            start = lineno - 1 - context//2
            try:
>               lines, lnum = findsource(frame)

/usr/lib/python2.7/inspect.py:1007: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

object = <frame object at 0x251a290>

    def findsource(object):
        """Return the entire source file and starting line number for an object.

        The argument may be a module, class, method, function, traceback, frame,
        or code object.  The source code is returned as a list of all the lines
        in the file and the line number indexes a line in that list.  An IOError
        is raised if the source code cannot be retrieved."""

        file = getfile(object)
        sourcefile = getsourcefile(object)
>       if not sourcefile and file[0] + file[-1] != '<>':
E       IndexError: string index out of range

/usr/lib/python2.7/inspect.py:528: IndexError
================================== 1 failed in 0.45 seconds ===================================

Probably an example of what http://stackoverflow.com/questions/16075850/inspect-getsource-and-file-both-dont-work-with-pytest vaguely reported.


@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


Can you confirm it also fails with pytest-2.3.5?

@pytestbot
Copy link
Contributor Author

Original comment by Peter Feiner (BitBucket: peterfeiner, GitHub: peterfeiner):


Just tried pytest-2.3.5. It also fails.

@pytestbot
Copy link
Contributor Author

Original comment by Peter Feiner (BitBucket: peterfeiner, GitHub: peterfeiner):


Root problem is in execnet. See https://bitbucket.org/hpk42/execnet/issue/15/remote_exec-breaks-inspectstack.

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


Thanks, Peter, for fixing it there. Is the problem now gone for pytest-xdist?

@pytestbot
Copy link
Contributor Author

Original comment by Peter Feiner (BitBucket: peterfeiner, GitHub: peterfeiner):


My pleasure :-) The problem is now gone from pytest-xdist.

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


resolved in execnet (which is not yet released).

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant