pytest-dev / pytest-dev/pytest-rerunfailures

ImportError: cannot import name ‘resultlog_key‘ from ‘_pytest.resultlog‘

Open
#236 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
477
Forks
107
Avg merge
2d 14h
Merged PRs (30d)
21

Description

def worker_internal_error(self, node, formatted_error):
        """
        pytest_internalerror() was called on the worker.
    
        pytest_internalerror() arguments are an excinfo and an excrepr, which can't
        be serialized, so we go with a poor man's solution of raising an exception
        here ourselves using the formatted message.
        """
        self._active_nodes.remove(node)
        try:
>           assert False, formatted_error
E           AssertionError: Traceback (most recent call last):
E               File "/usr/local/lib/python3.7/site-packages/_pytest/main.py", line 269, in wrap_session
E                 session.exitstatus = doit(config, session) or 0
E               File "/usr/local/lib/python3.7/site-packages/_pytest/main.py", line 323, in _main
E                 config.hook.pytest_runtestloop(session=session)
E               File "/usr/local/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
E                 return self._hookexec(self, self.get_hookimpls(), kwargs)
E               File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 92, in _hookexec
E                 return self._inner_hookexec(hook, methods, kwargs)
E               File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 86, in <lambda>
E                 firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
E               File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
E                 return outcome.get_result()
E               File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
E                 raise ex[1].with_traceback(ex[2])
E               File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
E                 res = hook_impl.function(*args)
E               File "/usr/local/lib/python3.7/site-packages/xdist/remote.py", line 115, in pytest_runtestloop
E                 self.run_one_test(torun)
E               File "/usr/local/lib/python3.7/site-packages/xdist/remote.py", line 131, in run_one_test
E                 self.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
E               File "/usr/local/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
E                 return self._hookexec(self, self.get_hookimpls(), kwargs)
E               File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 92, in _hookexec
E                 return self._inner_hookexec(hook, methods, kwargs)
E               File "/usr/local/lib/python3.7/site-packages/pluggy/manager.py", line 86, in <lambda>
E                 firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
E               File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
E                 return outcome.get_result()
E               File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
E                 raise ex[1].with_traceback(ex[2])
E               File "/usr/local/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
E                 res = hook_impl.function(*args)
E               File "/usr/local/lib/python3.7/site-packages/pytest_rerunfailures.py", line 593, in pytest_runtest_protocol
E                 check_options(item.session.config)
E               File "/usr/local/lib/python3.7/site-packages/pytest_rerunfailures.py", line 145, in check_options
E                 resultlog = _get_resultlog(config)
E               File "/usr/local/lib/python3.7/site-packages/pytest_rerunfailures.py", line 117, in _get_resultlog
E                 from _pytest.resultlog import resultlog_key
E             ImportError: cannot import name 'resultlog_key' from '_pytest.resultlog' (/usr/local/lib/python3.7/site-packages/_pytest/resultlog.py)
E           assert False
/usr/local/lib/python3.7/site-packages/xdist/dsession.py:190: AssertionError

Package Version:
pytest 7.3.2
pytest-rerunfailures 12.0

I know _pytest.resultlog was removed in pytest 6.1.0

search for source code:

 HAS_RESULTLOG = False
 try:
     from _pytest.resultlog import ResultLog
 
     HAS_RESULTLOG = True
 except ImportError:
     # We have a pytest >= 6.1
     pass
 def _get_resultlog(config):
     if not HAS_RESULTLOG:
         return None
     elif PYTEST_GTE_54:
         # hack
         from _pytest.resultlog import resultlog_key
 
         return config._store.get(resultlog_key, default=None)
     else:
        return getattr(config, "_resultlog", None)

so when I have a pytest >= 6.1 “from _pytest.resultlog import resultlog_key” should not be executed !
maybe because ”from _pytest.resultlog import ResultLog“ not reise Exception unexpected ,which means though i have a pytest >= 6.1 ,_pytest.resultlog was not removed?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pytest_rerunfailures.py, especially _get_resultlog and the HAS_RESULTLOG version check. Reproduce the import failure with pytest 7.3.2 and pytest-rerunfailures 12.0, then verify the result-log compatibility path no longer raises ImportError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.