Skip to content

use a custom error instead of calling pytest.fail #187

@12rambau

Description

@12rambau

Context

I'm currently building a pytest-regression spinoff (pytest-gee) dedicated to Google Earth Engine Python AP, the Google Earth Observation software. This as any Google product is just a monster API and the Python binding is a wrapper to build the correct json payload (earthengine-api). As a consequence my pytest plugin do 2 things, first check that the API call I'm building is still the same (by comparing yaml files) and if not, make a real call to the API to check the server response.

This reduce the computation time and cost of running the tests as the Google team is making lots of efforst to avoid non-regression.

In this context something like :

def test_list_regression(ee_list_regression):
    """Test the ee_list_regression fixture."""
    data = ee.List([1, 2, 3])
    ee_list_regression.check(data)

will create 2 files:

  • /serialized_list_regression.yml
  • /list_regression.yaml

the check on "serialized" is performed with perform_regression_check and I would like to silence anything that would happen there. basically if it works, good, if not I make a call to the API.

Issue

In the perform_regression_check method, you are directly calling pytest.fail when the file is not there and/or the file is regenerated. The problem for me is that pytest is not exposing the error type used by pytest.fail making it impossible to catch it is a supress context manager nor a try ... catch statement.

Could you explain why you didn't simply raised a fileNotFound error instead ? and if not clear reason would you be open to change this behavior ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions