Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test assertion issue #327

Open
NotoriousPyro opened this issue Mar 28, 2022 · 0 comments
Open

Test assertion issue #327

NotoriousPyro opened this issue Mar 28, 2022 · 0 comments

Comments

@NotoriousPyro
Copy link

NotoriousPyro commented Mar 28, 2022

assert third_time[0] != first_time

While I was messing about with the JSON serialization, where I changed the default to json, the fourth assertion in this test started randomly failing. I fixed this, because it was caused by me when I was integrating #209 into the fork. However, I couldn't help but notice the highlighted line for assertion 3, and wonder why it was selecting item [0] which seemed to be different to the rest of the assertions. Surely if we are getting the data from test_client "cached" or not, we shouldn't assert differently from looking at this test.

I printed all the responses and the one which stood out was the line highlighted, it printed 1 (an int) while the other lines printed a float number, every time I ran the test it was the same. Printing item[0] other x_time variables and you get 1, so the third assertion if 1 != <floating point> is likely to always pass.

Additionally, none of the code inside the redefined functions view_works changes throughout any of the tests, and when you inspect the actual value for third_time you find it is the same as first_time and so the test would always assert true because the function never changes and the third result designed to catch it doesn't have the correct assertion.

To fix this, I changed it to using datetime and timedelta: https://github.com/NotoriousPyro/flask-caching-json/blob/591f89e4f09e90aad25b7027672d342c41349426/tests/test_view.py#L444
And now we can assert on the real returned value: https://github.com/NotoriousPyro/flask-caching-json/blob/591f89e4f09e90aad25b7027672d342c41349426/tests/test_view.py#L457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant