CFMTech / pytest-monitor

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

add support for unittests (via pytest) #39

Open stas00 opened 3 years ago

stas00 commented 3 years ago

As discussed here https://github.com/CFMTech/pytest-monitor/pull/38 pytest almost fully supports unittest, but currently pytest-monitor skips all unittest-based tests.

I originally proposed to document this, but it was suggested that perhaps this can be fixed and pytest-monitor could support unittest-based tests too, which would be awesome.

So as suggested opening this Issue to track the feasibility/progress on this front.

js-dieu commented 3 years ago

Thanks for the suggestion.

As stated in the PR #38 I need to understand both sequence and objects that lies beneath. I'll put details about that here for clarity's sake.

dremdem commented 3 years ago

As discussed here #38 pytest almost fully supports unittest, but currently pytest-monitor skips all unittest-based tests.

I originally proposed to document this, but it was suggested that perhaps this can be fixed and pytest-monitor could support unittest-based tests too, which would be awesome.

So as suggested opening this Issue to track the feasibility/progress on this front.

Will be waiting for unittest support ;)

js-dieu commented 3 years ago

Hello

I've been more busy than expected but I have been able to made some progress. It does not seem feasible to "inject" the probing system of pytest-monitor for unittest function/classes (The probe relies on Generic Test item with standard testing protocol).

However, I've found an interesting way of injection that seems promising. I'll try to dig in the next days.

js-dieu commented 3 years ago

Hello @dremdem @stas00

I managed to intercept the test function for each unittest. I can obtain measures which seems fine. I am actually a bit stuck for reporting these measures since I have no access to the session. I tried to use hook reports, but I am unsuccessful so far. I have other ideas to manage my way through the unittest protocol but it seems hacky.

Keep you posted.

ChaoticRoman commented 2 years ago

Dear @js-dieu,

thank you for the great plugin! Would you mind to share your progress in a branch? This feature would help me a lot and maybe I can help with the progress.

Regards

Roman

ChaoticRoman commented 2 years ago

Follow up: It is working here outside of the pytest-monitor:

https://github.com/ChaoticRoman/pytest-monitor-example/blob/custom_memory_profiler/unittestit.py

js-dieu commented 2 years ago

Hello @ChaoticRoman

I unfortunately lost the development after entering an erroneous command. That being said, I might be able to recode what I did, though your snippet is neat for starting it again. Keep you posted!

ChaoticRoman commented 2 years ago

Bloomberg guys just released this: https://github.com/bloomberg/memray

Will check it out and let you know.

ChaoticRoman commented 2 years ago

Memray and pytest-memray looks cool but have this exactly same issue, reported: https://github.com/bloomberg/pytest-memray/issues/6