-
Notifications
You must be signed in to change notification settings - Fork 353
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
TST: Don't hard code server port in tests #1690
base: master
Are you sure you want to change the base?
Conversation
2d070ab
to
c31af10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance all looks well here, but I have not yet reviewed in detail.
I have one main comment for you to consider before moving on.
if "give_path" in self.headers: | ||
return self._respond(200, data=json.dumps({"path": self.path}).encode()) | ||
if "redirect" in self.headers and file_path != "/index/realfile": | ||
new_url = f"http://127.0.0.1:{port}/index/realfile" | ||
new_url = f"http://127.0.0.1:{self.server.server_port}/index/realfile" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.server.realfile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.server
is the HTTPServer
, not the server
fixture, and doesn't have a realfile
attribute. But this could probably use _make_realfile
instead.
httpd = HTTPServer(server_address, HTTPTestHandler) | ||
th = threading.Thread(target=httpd.serve_forever) | ||
th.daemon = True | ||
th.start() | ||
try: | ||
yield f"http://127.0.0.1:{port}" | ||
yield f"http://127.0.0.1:{httpd.server_port}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are choosing to become port agnostic, this may be a good time to also become server address agnostic. httpd.server_name
should be populated here, and might be other than the standard loopback, e.g., for systems that are IPv6 only.
@@ -185,4 +197,5 @@ def serve(): | |||
@pytest.fixture(scope="module") | |||
def server(): | |||
with serve() as s: | |||
yield s | |||
server = SimpleNamespace(address=s, realfile=_make_realfile(s)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
named_tuple or dict? I haven't really seen SimpleNamespace used much. In effect, it's a dictionary here. May as well include server name and other strings that are templated throughout the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that might be a bit overkill for tests.
Are there really any other strings that could be put in here? I replaced all the realfile
s which seemed like the only common ones.
This allows running tests in parallel without running into "Port already in use" errors.
92917e1
to
ed65ca2
Compare
This allows running tests in parallel without running into "Port already in use" errors.