miLibris / flask-rest-jsonapi

Flask extension to build REST APIs around JSONAPI 1.0 specification.
http://flask-rest-jsonapi.readthedocs.io
MIT License
598 stars 153 forks source link

Resetting `api.app.view_functions` to the initial state #207

Open sturmianseq opened 3 years ago

sturmianseq commented 3 years ago

This PR aims to improve test reliability of test test_api by resetting api.app.view_functions to the initial state by calling method clear

The test can fail in this way by running pip3 install pytest-repeat; python3 -m pytest --count=2 $test_path:

    def test_api(app, person_list):
        api = Api(app)
>       api.route(person_list, 'person_list', '/persons', '/person_list')

...

        if view_func is not None:
            old_func = self.view_functions.get(endpoint)
            if old_func is not None and old_func != view_func:
>               raise AssertionError(
                    "View function mapping is overwriting an existing"
                    f" endpoint function: {endpoint}"
                )
E               AssertionError: View function mapping is overwriting an existing endpoint function: person_list

It may be better to clean state pollutions so that some other tests won't fail in the future due to the shared state pollution.