Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#236 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
testing-qa

Hướng nghiên cứu

Bắt đầu trong pytest_rerunfailures.py, đặc biệt là _get_resultlog và kiểm tra phiên bản HAS_RESULTLOG. Tái hiện lỗi import với pytest 7.3.2 và pytest-rerunfailures 12.0, sau đó xác minh rằng đường dẫn tương thích result-log không còn gây ra ImportError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Python
Star
480
Fork
110
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pytest-dev/pytest-rerunfailures

Tất cả issue của pytest-dev/pytest-rerunfailures

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.