-
Notifications
You must be signed in to change notification settings - Fork 39
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
Change test suite web server (gunicorn) launch to a proper pytest fixture #3002
Conversation
Instead of always start/stopping gunicorn at the start/end of an integration test session, this makes it a session fixture that tests can depend on directly. The new fixture is defined at the top-level `conftest.py` in order for it to be reusable by any part of the test suite.
This should be more or less common to all test suites.
This includes removing the unused environment variable TARGETURL, as the URL is more or less decided by the gunicorn fixture and not by some force external to pytest. Also cleans up unused imports, and import order of some imports, because why not?
Most, if not all, the functional tests need a base URL for the web server and already depend on the base_url fixture. The URL is no longer received from the environment, but from the gunicorn fixture, so this simply makes the base_url fixture a proxy for the gunicorn fixture.
The old code would break down if the base url did not contain a trailing slash. Using `urljoin` should be more robust than joining URL strings ourselves.
🦙 MegaLinter status: ✅ SUCCESS
See detailed report in MegaLinter reports |
Test results 9 files 9 suites 8m 36s ⏱️ Results for commit 74427b1. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3002 +/- ##
==========================================
+ Coverage 56.68% 60.32% +3.63%
==========================================
Files 602 602
Lines 43713 43713
Branches 48 48
==========================================
+ Hits 24778 26368 +1590
+ Misses 18923 17333 -1590
Partials 12 12 ☔ View full report in Codecov by Sentry. |
This cleans up the test suite somewhat, by changing how gunicorn is launched to provide a fully operational NAV web ui for the test suite.
Gunicorn is needed both by the integration and the functional test suites, but its launch was duplicated in both suites'
conftest.py
files. Also, as part of thepytest_configure()
andpytest_unconfigure()
functions of those modules, the gunicorn server would always be launches on every test session, regardless of which tests were selected.This changes the mechanism to properly function as a pytest fixture, which means that tests can now explicitly declare a dependency on the gunicorn test web server. This ensures it will only ever be launched when tests that use it are selected.
The PR ensures existing tests that need the web server are made dependent on the new fixture, and removes a bit of cruft in the surrounding code as well.
Anti-cruft measures include removing test suite redundancies by factoring out redundant setup code and moving it to the top-level
tests/conftest.py
file. This was in some ways necessary for the test suite to continue working.This was extracted and adapted from #2675.