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

Fix date-sensitive acceptance tests #97

Closed
jantman opened this issue Jul 9, 2017 · 0 comments
Closed

Fix date-sensitive acceptance tests #97

jantman opened this issue Jul 9, 2017 · 0 comments

Comments

@jantman
Copy link
Owner

jantman commented Jul 9, 2017

A lot of the acceptance tests are date-sensitive and have issues with breaking depending on date. It's probably time I look into a better way to fix these. It's a bit complicated to use freezegun since the acceptance tests run a live flask server, but there's probably some way to fix this... even if it means hacking some test helpers into the main code itself... like doing all date lookups from one function that can be overridden by a magic environment variable.

  • If this is done, we'd probably need to audit the DB code for any SQL that uses DB-side current date operations (other than an INSERT). SQLAlchemy's before_cursor_execute Event should let us capture all SQL that's sent to the DB. If running in pytest, we could register a handler for that event (it'd need to be in the code for the flask app as well, so either in the settings file or via some awful "include this code during tests" trigger) that looks for any of MySQL's current-date functions in the SQL, and raises an exception if one is found.
  • We'll need something to ensure that Python's built-in date methods aren't called during tests. Not sure what the best way to do this is... perhaps we could use pytest-profiling data? Or should we just assume that over time, we'll find any uses of it because the tests will fail?

There's pytest-freezegun. Might just be able to set that up as an autouse fixture for the unit tests. Then I'd just need to figure out how to do it in the LiveServer, which probably means the above (some hack-y "use this one method for all calls to get date or time, and have that method do something special during tests").

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

No branches or pull requests

1 participant