Skip to content

Latest commit

 

History

History
84 lines (65 loc) · 3.47 KB

configuration.md

File metadata and controls

84 lines (65 loc) · 3.47 KB

Configuration

Contents

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.

Samples

You can find a sample configuration here and a sample test that uses it here.

Examples

A sample approvaltests_config.json:

{
  "subdirectory": "approved_files"
}

How to configure a default reporter for your system

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())

snippet source | anchor

The problem is you need to do this before you do anything else. Here are suggestions on how to do that.

Unittest

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()

snippet source | anchor

def configure_approvaltests():
    set_default_reporter(my_preferred_reporter)

snippet source | anchor

Pytest

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()

snippet source | anchor