smarie / python-pytest-harvest

Store data created during your `pytest` tests execution, and retrieve it at the end of the session, e.g. for applicative benchmarking purposes.
https://smarie.github.io/python-pytest-harvest/
BSD 3-Clause "New" or "Revised" License
61 stars 8 forks source link

Parametrized fixture unions (pytest-cases) do not appear nicely in the results dict and dataframe #51

Closed smarie closed 3 years ago

smarie commented 3 years ago
from pytest_cases import parametrize_with_cases, fixture, parametrize

@fixture
def a():
    return

class CaseFoo:
    @parametrize(b=[1, 4], c=[2])
    def case_a(self, a, b, c):
        return

@parametrize_with_cases("c", cases=CaseFoo)
def test_bar(c):
    pass

def test_synthesis(module_results_df):
    print(module_results_df.T)

yields

test_id                                 test_bar[a-b=1-c=2]                        test_bar[a-b=4-c=2]
pytest_obj        <function test_bar at 0x0000025023023AE8>  <function test_bar at 0x0000025023023AE8>
status                                               passed                                     passed
duration_ms                                          0.4035                                     0.3943
test_bar_c_param                                    c/P0F/a                                    c/P0F/a
a__param                                             (1, 2)                                     (4, 2)
smarie commented 3 years ago

module_results_df['test_bar_c_param_id'] = module_results_df['test_bar_c_param'].apply(lambda o: o.get_alternative_id())

It correctly yields the new result:

test_id                                    test_bar[a-b=1-c=2]                        test_bar[a-b=4-c=2]
pytest_obj           <function test_bar at 0x0000025023023AE8>  <function test_bar at 0x0000025023023AE8>
status                                                  passed                                     passed
duration_ms                                             0.4035                                     0.3943
test_bar_c_param                                       c/P0F/a                                    c/P0F/a
a__param                                                (1, 2)                                     (4, 2)
test_bar_c_param_id                                          a                                          a