-
Notifications
You must be signed in to change notification settings - Fork 339
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
Move thread activation to start method #1032
Conversation
Note: The failing tests here aren't failing, it's just an issue with the codecov upload. |
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'm not opposed to this, but needs a couple of changes:
- To keep backward compat (not that it's a public interface, but who knows), let's add a
*, start: bool = True
argument to__init__
, and add a call toself.start
ifstart
is true. You will then need to passstart=False
. - The
inc_thread_sharing
part needs to be done instart
, not in__init__
, to match thestop
.
Thanks for the quick feedback! I did both of these, then went a little ham and took it a step beyond. This code was a little smelly. Imports inside the constructor, messing around with threads, etc. I refactored it to move all imports to the top, and it's now subclassing If I went too hard here, I'm happy to back off and just implement the requested changes. |
Alright, tests failing now. Looks like I'm misunderstanding something about these imports. Is there an explanation I missed somewhere about why imports are happening in a function instead of the top of the module? |
importing |
Backed off on the subclassing decision. I spent way too much time trying to implement a lazy import mechanism just to have it fall on its face. I very much dislike the imports inside methods. Makes my heart hurt. I don't know enough about this library to really understand what a good alternative would be though, so the code smells get to stay! |
@bluetech Anything blocking this one? |
pytest_django/fixtures.py
Outdated
@@ -538,6 +538,7 @@ def live_server(request): | |||
|
|||
server = live_server_helper.LiveServer(addr) | |||
request.addfinalizer(server.stop) | |||
|
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.
pytest_django/live_server_helper.py
Outdated
port = int(port_str) | ||
except ValueError: | ||
host = addr | ||
port = 0 |
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 think the entire liveserver_kwargs
business was to avoid this line, i.e. not duplicate Django's default in case it changes.
Thanks @samamorgan. I rebased and removed unrelated changes from the diff. Merging now. |
This moves activation of
LiveServer.thread
to a method. My primary motivation here is to delay thread activation so I can change the parameters of the thread in an overridenlive_server
fixture. This provides a work-around to issue #294 using the following override: