CFMTech / pytest-monitor

Pytest plugin for analyzing resource usage during test sessions
MIT License
173 stars 16 forks source link

pytest.skip() in a fixture causes an AttributeError for monitor_results during teardown #50

Closed altendky closed 2 years ago

altendky commented 2 years ago

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):

Additional context Template issues corrected in https://github.com/CFMTech/pytest-monitor/pull/49.

Naive "fix" submitted in https://github.com/CFMTech/pytest-monitor/pull/51.

js-dieu commented 2 years ago

Hi

thanks for spotting it and the associated PR!

altendky commented 2 years ago

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.

js-dieu commented 2 years ago

I'll make the release by end of week.

js-dieu commented 2 years ago

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

altendky commented 2 years ago

Hey, no worries. I've been able to keep myself busy. :] Thanks for working through the CI hassles and getting it out. Cheers.