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

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

Open
liaoqihan opened this issue Sep 2, 2023 · 0 comments

Comments

@liaoqihan
Copy link

liaoqihan commented Sep 2, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant