py.test ВНУТРЕННЯЯ ОШИБКА ›IndexError: индекс списка вне допустимого диапазона

Я работаю над Ubuntu 15.04:

платформа linux - Python 3.4.3, pytest-2.8.3, py-1.4.31, pluggy-0.3.1 корневой каталог: / home / barrios / code / testpytest, inifile:

Внутри свежего virtualenv я построил следующую структуру проекта:

myapp/
    __init__.py
    myapp.py
tests/
    tests.py
setup.py

Следуя различным сообщениям здесь, я обнаружил, что нужно либо установить PYTHONPATH в корень моего проекта, либо вызвать py.test с помощью:

PYTHONPATH=. py.test tests/tests.py

myapp.py выглядит так:

class Foo:
    def __init__(self):
        self.bar = None

    def set_bar(self, val):
        self.bar = val

tests.py:

from myapp import Foo

class TestFoo:
    def setup_method(self, method):
        self.foo = Foo()

    def teardown_method(self):
        self.foo.bar = None

    def test_set_bar(self):
        self.foo.set_bar(7)
        assert self.foo.bar is 7

Читая этот пост, я также поместил это в свой __init__ .py:

from .myapp import Foo

__all__ = ['Foo']

Я могу сделать

>>> from myapp import Foo

в консоли Python и

$> pip install -e .

с терминала.

Но, тем не менее, py.test жалуется на внутреннюю ошибку:

(venv)barrios@tuxedo:~/code/testpytest$ PYTHONPATH=. py.test tests/tests.py
=============================================================== test session starts ===============================================================
platform linux -- Python 3.4.3, pytest-2.8.3, py-1.4.31, pluggy-0.3.1
rootdir: /home/barrios/code/testpytest, inifile:
collected 1 items

tests/tests.py .
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 90, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 121, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 146, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 77, in runtestprotocol
INTERNALERROR>     nextitem=nextitem))
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/skipping.py", line 170, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 227, in pytest_runtest_makereport
INTERNALERROR>     style=item.config.option.tbstyle)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/python.py", line 740, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 404, in _repr_failure_py
INTERNALERROR>     style=style, tbfilter=tbfilter)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 412, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 590, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 577, in repr_traceback
INTERNALERROR>     last = traceback[-1]
INTERNALERROR>   File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 284, in __getitem__
INTERNALERROR>     val = super(Traceback, self).__getitem__(key)
INTERNALERROR> IndexError: list index out of range

Я не совсем уверен, что сообщать о проблеме в багтрекере py.test или если я все еще делаю что-то не так?


person barrios    schedule 05.12.2015    source источник


Ответы (1)


Вашему методу разборки не хватает второго аргумента, то есть method:

def teardown_method(self, method):

Внимательно прочтите документы здесь: https://pytest.org/latest/xunit_setup.html

person matino    schedule 05.12.2015
comment
TNX, а не должно ли быть более конкретного сообщения об ошибке? Внутренняя ошибка не очень помогает при отладке. Считается ли такое поведение py.test ошибкой? - person barrios; 06.12.2015