-
Notifications
You must be signed in to change notification settings - Fork 234
Use Config.invocation_params for consistent worker initialization #448
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
Conversation
initializing the config the same way everywhere is structurally a good idea i believe however that the main config initialization process needs some solid and api breaking work to support that sanely |
You mean If we can get this working with |
im totally fine with having sometihng that works a little bit better, but we will have to break api from he pytestside a few times to get things work nice |
Cool, sounds like a plan then.
We don't really have an API to properly initialize the config objects from the command line arguments today, do we? I'm thinking, for starters, an API to create the config object from config = Config.from_args_and_plugins(args, plugins) But we should brainstorm how to initialize both config and session objects so one can selectively run certain stages (say only collection) using public APIs and without having to manually call hooks. I believe some niche use cases would greatly benefit from it, for example IDE launchers. |
Great news! With pytest-dev/pytest#5564, all tests in This leads me to believe this is indeed the way to go. We can try to nail this down after |
8bfa02a
to
6bf9672
Compare
Decided to keep the old way still working for now. Fix pytest-dev#6 Fix pytest-dev#445
6bf9672
to
953a3f0
Compare
@RonnyPfannschmidt I think this is now ready for review. 👍 |
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.
lovely, great job 👍
@@ -236,10 +238,14 @@ def shutting_down(self): | |||
def setup(self): | |||
self.log("setting up worker session") | |||
spec = self.gateway.spec | |||
args = self.config.args | |||
if hasattr(self.config, "invocation_params"): | |||
args = [str(x) for x in self.config.invocation_params.args or ()] |
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.
Wouldn't this give unwanted arguments to the worker?
I'm investigating why pytest-cov's test suite is broken on 0.30 and invocation_params.args has lots of stuff while config.args is just the test file.
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.
@nicoddemus
Can you comment, please?
(I'm currently looking into getting pytest-cov's CI to pass again so this would help there)
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.
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.
@nicoddemus I guess I'm just confused about what's wrong with the latest pytest/xdist/cov combination (it's broken in some situations). Any explanation about how the all works would help me debug it.
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.
Not sure myself, but the latest implementation just forwards all the parameters given in the command line to the workers, making them initialize the same way as the master node.
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.
@nicoddemus the way I understand this the problem is that option_dict is empty in the new "invocation_params mode", thus plugins like pytest-cov don't have the necessary options to initialize. Am I missing something?
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.
Thus plugins like pytest-cov don't have the necessary options to initialize.
Unless pytest-cov is trying to get the options from pytest-xdist structures instead of config.getoption
, it should just work. The workers should now be initializing the same way as the master node/without xdist, so all the options should be there.
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.
@nicoddemus the problem is that none of the plugin options are there when stuff like --dist=load --tx=popen//chdir=1
is used. When using -n 1
everything is fine.
@@ -236,10 +238,14 @@ def shutting_down(self): | |||
def setup(self): | |||
self.log("setting up worker session") | |||
spec = self.gateway.spec | |||
args = self.config.args | |||
if hasattr(self.config, "invocation_params"): | |||
args = [str(x) for x in self.config.invocation_params.args or ()] |
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.
@nicoddemus the problem is that none of the plugin options are there when stuff like --dist=load --tx=popen//chdir=1
is used. When using -n 1
everything is fine.
option_dict = {} | ||
else: | ||
args = self.config.args | ||
option_dict = vars(self.config.option) | ||
if not spec.popen or spec.chdir: | ||
args = make_reltoroot(self.nodemanager.roots, args) |
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.
@nicoddemus I think now I correctly identified the cause of the problem. In the new code the args stripping matters cause the old option_dict is no more, while previously this stripping had no effect.
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.
Sorry, what "stripping" you mean? Can you please clarify?
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.
@nicoddemus see #491 - make_reltoroot removes anything that ain't a valid path (like the arguments I need).
EDIT
Decided to keep the old way still working for now.
Fix #6
Fix #445
ORIGINAL POST
While investigating a recent node id bug (#445) I decided to play
with config initialization, around the idea of initializing the config
on the remote exactly how we initialize the config object on pytest.main()
One thing that immediately broke all tests was inprocess pytester runs,
but other than that just a few tests failed which I find encouraging.
While this patch is in no way even remotely ready, I would like to get
opinions if the overall idea of initializing the config object
like this is sound.