You can create directory level configuration for approvals.
To do this create a file named approvaltests_config.json
and place it in the same directory as your test.
As of right now, the only configuration that you can do is to add subdirectories where the approved and received files will show up.
There is nothing that you need to do in the tests themselves to use this.
You can find a sample configuration here and a sample test that uses it here.
A sample approvaltests_config.json
:
{
"subdirectory": "approved_files"
}
If you don't like the standard default for reporting and wish to change it everywhere this is the recommended way to do it.
set_default_reporter(ReporterByCopyMoveCommandForEverythingToClipboard())
The problem is you need to do this before you do anything else. Here are suggestions on how to do that.
While some test frameworks allow for this, our recommended suggestion is to do it directly in Python by using the __init__.py
below.
note: Please be aware that this will not override the reporters that are specified in your tests, as approval tests uses the principle of least surprise.
# From __init__.py
configure_approvaltests()
def configure_approvaltests():
set_default_reporter(my_preferred_reporter)
Alternatively, pytest allows for the creation of a session scoped autouse fixture in the conftest.py file in Pytest. Here's a blog with an example
Here's the code for implementing it in conftest.py
(so skip the code in __init__.py
):
@pytest.fixture(scope="session", autouse=True)
def set_default_reporter_for_all_tests():
configure_approvaltests()