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

Change test suite web server (gunicorn) launch to a proper pytest fixture #3002

Merged
merged 5 commits into from
Sep 24, 2024

Conversation

lunkwill42
Copy link
Member

@lunkwill42 lunkwill42 commented Sep 20, 2024

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 the pytest_configure() and pytest_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.

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.
Copy link

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON black 987 0 23.75s
✅ PYTHON flake8 987 0 440.06s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

Copy link

Test results

    9 files      9 suites   8m 36s ⏱️
2 107 tests 2 107 ✅ 0 💤 0 ❌
3 953 runs  3 953 ✅ 0 💤 0 ❌

Results for commit 74427b1.

@lunkwill42 lunkwill42 requested a review from a team September 20, 2024 16:09
@lunkwill42 lunkwill42 marked this pull request as ready for review September 20, 2024 16:09
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.32%. Comparing base (18db455) to head (74427b1).
Report is 23 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

Base automatically changed from test/webcrawler-as-single-test to master September 24, 2024 10:51
@lunkwill42 lunkwill42 merged commit 02f9bcd into master Sep 24, 2024
13 checks passed
@lunkwill42 lunkwill42 deleted the test/gunicorn-as-fixture branch September 24, 2024 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants