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

InternalError: AttributeError: 'str' object has no attribute 'relto' #1133

Closed
nicoddemus opened this issue Oct 12, 2015 · 2 comments
Closed
Labels
type: bug problem that needs to be addressed

Comments

@nicoddemus
Copy link
Member

It seems there are other situations where Entry.path might return strings rather than py.path.local objects than just generated code. This is happening on pytest-qt AppVeyor on Python 2.7. 👻

I have modified my local code to print entry.path:

def filter_traceback(entry):
    # entry.path might sometimes return a str() object when the entry
    # points to dynamically generated code
    # see https://bitbucket.org/pytest-dev/py/issues/71
    raw_filename = entry.frame.code.raw.co_filename
    is_generated = '<' in raw_filename and '>' in raw_filename
    if is_generated:
        return False
    print('BRUNO', entry.path)
    return entry.path != cutdir1 and not entry.path.relto(cutdir2)

And this is what I see:

('BRUNO', 'pytestqt\\logging.py')

Not sure how to reproduce it, but anyway it seems to me we should take in account that entry.path might not be a py.path.local object. This fixes my test suite:

def filter_traceback(entry):
    # entry.path might sometimes return a str() object when the entry
    # points to dynamically generated code
    # see https://bitbucket.org/pytest-dev/py/issues/71
    raw_filename = entry.frame.code.raw.co_filename
    is_generated = '<' in raw_filename and '>' in raw_filename
    if is_generated:
        return False    
    p = py.path.local(entry.path)
    return p != cutdir1 and not p.relto(cutdir2)

@RonnyPfannschmidt @hpk42 any ideas?

============================= test session starts =============================
platform win32 -- Python 2.7.10, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
PyQt4 4.11.4 -- Qt runtime 4.8.7 -- Qt compiled 4.8.7
rootdir: c:\users\bruno\appdata\local\temp\pytest-of-Bruno\pytest-2433\testdir\test_logging_mark_with_invalid_argument0, inifile:
plugins: qt-1.7.0
collected 1 items

test_logging_mark_with_invalid_argument.py ('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\runner.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\runner.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', local('X:\\pytest-qt\\.tox\\py27-pyqt4\\lib\\site-packages\\_pytest\\vendored_packages\\pluggy.py'))
('BRUNO', 'pytestqt\\logging.py')

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\main.py", line 90, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\main.py", line 121, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 301, in __call__
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 299, in <lambda>
INTERNALERROR>     outcome = _CallOutcome(lambda: self.oldcall(hook, hook_impls, kwargs))
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\main.py", line 146, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 301, in __call__
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 299, in <lambda>
INTERNALERROR>     outcome = _CallOutcome(lambda: self.oldcall(hook, hook_impls, kwargs))
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 253, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\runner.py", line 72, in runtestprotocol
INTERNALERROR>     rep = call_and_report(item, "setup", log)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\runner.py", line 121, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 301, in __call__
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 299, in <lambda>
INTERNALERROR>     outcome = _CallOutcome(lambda: self.oldcall(hook, hook_impls, kwargs))
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 253, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 249, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\skipping.py", line 170, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\runner.py", line 227, in pytest_runtest_makereport
INTERNALERROR>     style=item.config.option.tbstyle)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\python.py", line 726, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\main.py", line 397, in _repr_failure_py
INTERNALERROR>     self._prunetraceback(excinfo)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\python.py", line 709, in _prunetraceback
INTERNALERROR>     ntraceback = ntraceback.filter(filter_traceback)
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\py\_code\code.py", line 299, in filter
INTERNALERROR>     return Traceback(filter(fn, self))
INTERNALERROR>   File "X:\pytest-qt\.tox\py27-pyqt4\lib\site-packages\_pytest\python.py", line 60, in filter_traceback
INTERNALERROR>     return entry.path != cutdir1 and not entry.path.relto(cutdir2)
INTERNALERROR> AttributeError: 'str' object has no attribute 'relto'
@nicoddemus nicoddemus added the type: bug problem that needs to be addressed label Oct 12, 2015
@The-Compiler
Copy link
Member

FWIW I see the same when I do tox -e py27-pyqt4 -- tests/test_logging.py in the pytest-qt repo on Debian.

@nicoddemus
Copy link
Member Author

I found a workaround: If I changedir=tests in my tox.ini, my suite passes.

My guess is that when running the tests inside the tox environment, the py.code.Code object was seeing the local pytestqt/logging.py file instead of the pytestqt.logging inside the tox environment. This was confusing Code.path function somehow, making it return a pure str object:

    @property
    def path(self):
        """ return a path object pointing to source code (note that it
        might not point to an actually existing file). """
        p = py.path.local(self.raw.co_filename)
        # maybe don't try this checking
        if not p.check():
            # XXX maybe try harder like the weird logic
            # in the standard lib [linecache.updatecache] does?
            p = self.raw.co_filename
        return p

Perhaps it loaded the code from __pycache__, but inside the tox environment that path is not found anymore?

It seems to me that filter_traceback should never rely that entry.path is a py.path.local instance, for safety. @hpk42, @RonnyPfannschmidt what do you guys think?

nicoddemus added a commit to pytest-dev/pytest-qt that referenced this issue Oct 14, 2015
It seems that inside the tox environment `entry.path` points
to the local "pytestqt/logging.py" file (importable from $CWD).
Changing the current directory to "tests" during the tox run
worksaround this problem.
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

2 participants