Ozon3Org / Ozon3

An open-source Python package to easily obtain real-time, historical, or forecasted air quality data for anywhere in the world. Reliable, accurate and simple.
GNU General Public License v3.0
66 stars 23 forks source link

Ozone tests inconsistency - pytest --disable-recording not fixing cassette recording issues #134

Closed Milind220 closed 2 years ago

Milind220 commented 2 years ago

Note: I created this separate issue for this topic, even though this is actually what was being discussed in #130

Description The tests show me that two tests are failing. When I tried @lahdjirayhan 's suggestion of running the following: pytest tests/test_get_city_forecast.py tests/test_get_coordinate_air.py --disable-recording Then 16/17 tests failed for really strange reasons.

Screenshots of the tests failing are attached below.

To Reproduce Steps to reproduce the behavior:

  1. Create a new conda virtual env with python 3.9
  2. setup the development environment as detailed in the CONTRIBUTING file
  3. run pytest in the root directory to see the two originally failing tests.
  4. run pytest tests/test_get_city_forecast.py tests/test_get_coordinate_air.py --disable-recording to see 16/17 tests fail

Expected behavior

Screenshots when I ran just pytest

Screenshot 2022-04-29 at 6 11 48 PM

when I ran pytest tests/test_get_city_forecast.py tests/test_get_coordinate_air.py --disable-recording

Screenshot 2022-04-29 at 6 12 36 PM

Environment

lahdjirayhan commented 2 years ago

Oh no, I forgot to add information about how to supply your own token 🤦🏼 , because eventually if we use --disable-recording, we're doing live requests (which will need our AQI token). I think I'll do some writeups right now to inform everyone (including myself) in the future about this; rather than writing the solution in this issue.

Hold my beer, I got this.

What we roughly need is as follows:

lahdjirayhan commented 2 years ago

For future visitors to this thread:

If you get vcr.errors.CannotOverwriteExistingCassetteException when running pytest, you probably need to use live connection (disable cassette recording) and see if the test passes. That exception is raised when the cassette file is not complete (there is a request in the test function that's not recorded in the cassette file).

If you get Exception: Your API token is invalid when running pytest --disable-recording, it's probably because you haven't supplied a working API token to the test suite. In turn, this will make the test suite uses a dummy token, which is obviously not a valid API token.

More about the test suite is explained in CONTRIBUTING.

lahdjirayhan commented 2 years ago

@Milind220 I just want to confirm, have you checked that the information provided in the PR is sufficient to solve the problem posed in this issue?

Milind220 commented 2 years ago

@lahdjirayhan Yes, fixed it perfectly! The token was all that was needed.

EDIT: I no longer see the 'not provided a token' issue, but now a different test fails. I ran pytest with recordings disabled here.

Screenshot 2022-04-30 at 12 00 53 PM

I'm having a hard time deciphering what this means. Do I understand correctly that the purpose of this test is to check that incorrectly entered coordinates are handled smoothly? Where did 50.805778 come from?