Jc2k/pytest-docker-tools

TypeError: 'NoneType' object is not subscriptable

bertpassek opened this issue · 10 comments

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/_pytest/main.py", line 323, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/_pytest/main.py", line 348, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/_pytest/runner.py", line 109, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/_pytest/runner.py", line 127, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "teardown", log, nextitem=nextitem))
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/_pytest/runner.py", line 217, in call_and_report
INTERNALERROR>     report: TestReport = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/foobar/.venv/lib/python3.9/site-packages/pytest_docker_tools/plugin.py", line 37, in pytest_runtest_makereport
INTERNALERROR>     fixture = fixturedef.cached_result[0]
INTERNALERROR> TypeError: 'NoneType' object is not subscriptable

pytest-docker-tools: 1.0.2

If this happens, pytest will stop running tests and status is always successful.

        if not hasattr(fixturedef, "cached_result"):
            continue
        fixture = fixturedef.cached_result[0]

fixturedef.cached_result is None in my case

Jc2k commented

Hi

I've recently started hitting this myself and haven't had chance to investigate. It turned out to be an interaction with another fixture (which as it happened was async). It was a legitimate bug in that projects fixture, and pytest-docker-tools was just masking thje error message. So it would be good to know what other fixtures are in play for this test and if you are testing async code.

Cheers

Jc2k commented

As i don't have a reproducer, does changing the code in question to this help?

        if not getattr(fixturedef, "cached_result", None):
            continue
        fixture = fixturedef.cached_result[0]

Hi,

i don't know exactly which fixture is involved, still trying to investigate. But it's a self written fixture with localstack for testing aws s3 stuff, don't know if there is any kind of async operation. I just opened a simple pr, yes this minor change would help a lot.

Thanks.

Jc2k commented

ah ok, i was hoping to find out what causes the situation so i could write a test. but it will have to remain a mystery :D

We got a whole bunch of fixtures, i might spend some more time to find something out, but it isn't that easy, async is not used as i can see right now.

Jc2k commented

I've pushed a tag with your fix in, when GH is finished the release should appear on pypi automatically: https://github.com/Jc2k/pytest-docker-tools/actions/runs/690281718

Thanks for your fast response.

Jc2k commented

NP, glad to help!

btw, pytest-docker-tool is pretty amazing, love it

Jc2k commented

Haha thanks, means a lot to get feed back like that! 🥳