ESSS / pytest-regressions

Pytest plugin for regression testing: https://pytest-regressions.readthedocs.io
MIT License
185 stars 36 forks source link

add a suffix parameter in regression fixture check method #161

Closed 12rambau closed 8 months ago

12rambau commented 9 months ago

Most of the time when I need to use "basename parameter" I in fact just want to test 2 things in the same test (yes I know it's not best practice but I have some legit reasons).

Instead of writting down the whole basename I would like to keep the original one which is my test name and simply add a suffix to it.

something like:

def test_something(data_regression):
    data_regression.check(data1, suffix="data1")
    data_regression.check(data2, suffix="data2")

Which would create a test_something_data1.yml and a test_something_data2.yml files. Do you think it would make sense to add it to the plugin ?

nicoddemus commented 9 months ago

Hi @12rambau,

TBH I think the check methods already have too many options/switches as it is.

I usually don't mind using a custom basename, say basename="something_data1"; the default being the test name is useful but not always a good choice because you might rename the test, and then you have to regenerate the files just because of that.

A little more verbose, but you can use the request fixture like this:

def test_something(data_regression, request):
    data_regression.check(data1, basename=f"{request.node.name}_data1")
    data_regression.check(data2, basename=f"{request.node.name}_data2")

I think this is a good compromise.

12rambau commented 9 months ago

That is an excellent compromise, let's leave this open I would like to document it in an admonition somewhere

nicoddemus commented 9 months ago

OK. thanks, appreciate it!