Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc update - collect a synthesis for all tests? #47

Open
shaunc opened this issue Dec 21, 2020 · 3 comments
Open

doc update - collect a synthesis for all tests? #47

shaunc opened this issue Dec 21, 2020 · 3 comments

Comments

@shaunc
Copy link

shaunc commented Dec 21, 2020

Having liked one of your packages, I decided to try another one! :)

I am trying to collect summary statistics on all of my tests. Tests are in a number of test modules in a bunch of different directories:

tests/
    __init__.py
    foo/
        __init__.py
        test_foo_foo.py
        test_foo_bar.py
    bar/
        __init__.py
        test_bar_baz.py
        test_bar_37.py

[just for illustration].

If I include test_synthesis(session_results_df) in any test_* leaf module I get the test syntheses up to that point... but there is no guarantee that it will be run depending on which tests I'm running from command line. I can't put it anywhere else, and have it run though. And if I included it in multiple places it runs multiple times.

I want to run test_synthesis once at the end ... no matter what. Is there a way to do this?

@shaunc
Copy link
Author

shaunc commented Dec 21, 2020

Aha!

@fixture(autouse=True, scope="session")
def session_stats():
    result = {}
    yield result
    collect_session_stats(result["session_results_df"])


@fixture(autouse=True)
def update_session_stats(session_results_df, session_stats):
    session_stats["session_results_df"] = session_results_df

I have these in the place I define all my fixtures, which is included in all of the test modules.

This solves my issue, I think. IMHO this would be great to have in the doc -- so leaving the issue open for the moment. However, feel free to close if you like.

@shaunc
Copy link
Author

shaunc commented Dec 21, 2020

Oops -- you're ahead of me again!

https://smarie.github.io/python-pytest-harvest/advanced_usage/

... the only thing I'd recommend is to mention this in the "regular docs" and/or have it more visible in the table of contents. It wasn't apparent that this section existed from just looking at the docs home page.

@shaunc shaunc closed this as completed Dec 22, 2020
@smarie
Copy link
Owner

smarie commented Dec 22, 2020

Great that you found the answer to you question ! I'll try to make this more explicit in the future. For this I'll leave the ticket open to remember

@smarie smarie reopened this Dec 22, 2020
@smarie smarie changed the title how to collect a synthesis for all tests? doc update - collect a synthesis for all tests? Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants