pytest-dev / pytest-rerunfailures

a pytest plugin that re-runs failed tests up to -n times to eliminate flakey failures
Other
369 stars 82 forks source link

AttributeError: 'str' object has no attribute 'reprcrash' while using pytest.mark.xfail #239

Closed metheuspsc closed 7 months ago

metheuspsc commented 9 months ago

Hello!

In my project, I use @pytest.mark.flaky(reruns=3, rerun_except=CustomException) using a specific custom Exception on a couple of tests. That causes the following error that looks similar to issue #175:

INTERNALERROR> E File "/Users/matheuspessoa/PycharmProjects/bigcommerce-adapter/venv/lib/python3.10/site-packages/pytest_rerunfailures.py", line 331, in _matches_any_rerun_except_error INTERNALERROR> E if re.search(rerun_regex, report.longrepr.reprcrash.message): INTERNALERROR> E AttributeError: 'str' object has no attribute 'reprcrash' INTERNALERROR> E assert False

So I suggest the same fix, which I tested locally and worked.


    for rerun_regex in rerun_except_errors:
        try:
            if re.search(rerun_regex, report.longrepr.reprcrash.message):
                return True
        except AttributeError:
            if re.search(rerun_regex, report.longreprtext):
                return True
    return False```python
danylokholodov commented 9 months ago

@metheuspsc Thank you for your solution! It helped.

icemac commented 9 months ago

@metheuspsc Could you please create a pull request for your fix?

metheuspsc commented 8 months ago

@metheuspsc Could you please create a pull request for your fix?

Done

icemac commented 7 months ago

Fixed by #240.