Skip to content

integration tests pytest fixture for running local http server #128

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

Closed
wants to merge 2 commits into from

Conversation

jonemo
Copy link
Contributor

@jonemo jonemo commented Jan 31, 2023

Currently not asking for a thorough review. I only want second (and third and fourth) opinion on whether to keep working on this or to cut my losses and scrap it.

Currently, we make requests to public websites like https://aws.amazon.com as part of our integration tests. While writing integration tests for HTTP client implementations, I figured: Why not instead run a server locally as a pytest fixture? Seems easy enough with Python's http.server.SimpleHTTPRequestHandler. Several rabbit hole explorations later I suddenly find myself passing ctyped locks into processes managed with multiprocessing and working around bugs in type annotations of the more obscure corners of Python's stdlib.

Benefits of having a local server in a fixture:

  1. Faster tests because no external network requests
  2. Tests can run without access to internet
  3. Tests no longer depend on websites that could change any day
  4. We can control the HTTP response, for example by reflecting request content
  5. Full control over details like HTTP version and header values (caveat: SimpleHTTPRequestHandler has limited support for features of HTTP, for example, no HTTP2)

Downsides of having a local server in a fixture:

  1. Spinning the server up and down takes time. (Mitigation: Scoping the fixture at module level amortizes this over many tests.)
  2. If for whatever reason the process and/or thread containing the server doesn't shut down, the test run stalls in difficult to debug ways.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jonemo jonemo marked this pull request as draft January 31, 2023 05:29
@jonemo jonemo force-pushed the http-integtest-local-server branch from 3f72dd1 to df1a796 Compare January 31, 2023 05:33
@jonemo jonemo closed this Feb 16, 2023
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

Successfully merging this pull request may close these issues.

1 participant