falconry / falcon

The no-magic web data plane API and microservices framework for Python developers, with a focus on reliability, correctness, and performance at scale.
https://falcon.readthedocs.io/en/stable/
Apache License 2.0
9.51k stars 937 forks source link

fix(tests): spawn servers via sys.executable #2047

Closed mgorny closed 2 years ago

mgorny commented 2 years ago

Summary of Changes

Spawn the servers (gunicorn, uvicorn, etc.) during tests through sys.executable rather than directly, in order to ensure that the test server is run using the same Python executable as the test suite. Otherwise, the test servers are started using the Python executable specified in their shebang and can therefore escape the virtualenv they are being run in.

This is particularly problem for tests being run from Gentoo ebuilds. We create a --system-site-packages venv to install falcon in, in order to test whether it works correctly against the dependencies installed on the system prior to installing it. However, the installed packages such as gunicorn specify /usr/bin/python* shebangs that override the venv and therefore make these servers unable to find venv-installed falcon. Running them via sys.executable ensures that they are started through Python installed in the venv.

Related Issues

n/a

Pull Request Checklist

codecov[bot] commented 2 years ago

Codecov Report

Merging #2047 (b367e85) into master (0066cb1) will not change coverage. The diff coverage is n/a.

@@            Coverage Diff            @@
##            master     #2047   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           63        63           
  Lines         6707      6707           
  Branches      1238      1238           
=========================================
  Hits          6707      6707           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0066cb1...b367e85. Read the comment docs.

mgorny commented 2 years ago

Heh I actually had this problem myself for uWSGI because I had that globally on my system, but it is unfortunately a harder task.

Yeah, I couldn't figure out how to make this work for uwsgi.

I'm thinking to myself though whether we shouldn't apply the same treatment for uvicorn for consistency too then?

Hmm, I did uvicorn in test_wsgi_servers but I see it's also in test_asgi_servers. I'll update the PR in a minute.

mgorny commented 2 years ago

Covered asgi tests now too.

mgorny commented 2 years ago

Well, I'm running a pretty big test environment here and gunicorn etc. just happen to be installed on the system. The goal's pretty much to try and see what could break on production systems — and I suppose people tend to run webservers there ;-).