pytest.skip() in a fixture causes an AttributeError for monitor_results during teardown
altendky opened this issue · 5 comments
Describe the bug
When a fixture skips via pytest.skip("some reason")
, teardown fails for pytest-monitor with AttributeError: 'Function' object has no attribute 'monitor_results'.
To Reproduce
https://replit.com/@altendky/SwiftCrimsonDownload-1
import subprocess
import pytest
@pytest.fixture
def a_fixture():
pytest.skip("because i want to show the issue")
def test_skipping(a_fixture):
pass
def main():
subprocess.run(["pytest", __file__])
if __name__ == "__main__":
main()
============================= test session starts ==============================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/runner/SwiftCrimsonDownload
plugins: monitor-1.6.2
collected 1 item
main.py sE [100%]
==================================== ERRORS ====================================
______________________ ERROR at teardown of test_skipping ______________________
request = <SubRequest 'prf_tracer' for <Function test_skipping>>
@pytest.fixture(autouse=True)
def prf_tracer(request):
if not PYTEST_MONITORING_ENABLED:
yield
else:
ptimes_a = request.session.pytest_monitor.process.cpu_times()
yield
ptimes_b = request.session.pytest_monitor.process.cpu_times()
> if not request.node.monitor_skip_test and request.node.monitor_results:
E AttributeError: 'Function' object has no attribute 'monitor_results'
/opt/virtualenvs/python3/lib/python3.8/site-packages/pytest_monitor/pytest_monitor.py:230: AttributeError
=========================== short test summary info ============================
ERROR main.py::test_skipping - AttributeError: 'Function' object has no attri...
========================= 1 skipped, 1 error in 0.13s ==========================
Expected behavior
No exception raised for this case.
Screenshots
Output shared as text above.
Desktop (please complete the following information):
- OS: Linux
Additional context
Template issues corrected in #49.
Naive "fix" submitted in #51.
Hi
thanks for spotting it and the associated PR!
Should I wait for a release or go ahead and work around this in some way in my code? I definitely don't mean to nag, just checking so I can decide my path forward.
Thanks for the quick turn around on reviews and merging.
I'll make the release by end of week.
Hello @altendky
Release done. Sorry for the delay, but circleci has erroneously flagged the project, preventing any build since.
Now available on pypi, conda to come shortly
Hey, no worries. I've been able to keep myself busy. :]
Thanks for working through the CI hassles and getting it out. Cheers.