Skip to content
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

Lock tests to a specific worker #365

Closed
boxed opened this issue Nov 8, 2018 · 7 comments
Closed

Lock tests to a specific worker #365

boxed opened this issue Nov 8, 2018 · 7 comments

Comments

@boxed
Copy link

boxed commented Nov 8, 2018

We have some tests that use an external resource that can't be used in parallel for the purposes of the tests. I would like a way to set a bunch of tests to only run on one worker. I'm not sure if this is covered by the ideas in #18

I think a simple approach would be to have a pytest marker pytest.mark.xdist_first_worker. One can think of generalizing this to mark.xdist_worker_gw0 etc, but I think this is probably just ripe for abuse and then you'll have to validate that you're trying to lock it to an existing worker (so gw_8 will give an error if you only have 3 workers). This seems like it could solve a bunch of the issues in #18 with a much simpler code change and much easier to document.

I tried to hack this together myself by looking at scheduler/load.py but I got a bit lost...

@nicoddemus
Copy link
Member

Hi @boxed,

Hmmm this is an interesting suggestion.

It might conflict with the proposal in #18 though, because it would create a conflict if an user marks tests with mark.xdist_first_worker that should execute in separate workers because of the fixtures they use.

Can you describe in more details why you want to specify tests in separate modules to run into a specific worker? We have currently --dist=loadscope and --dist=loadfile which might suite your needs already.

@boxed
Copy link
Author

boxed commented Nov 8, 2018

In our case the external resource is a single sign on service that we hard reset around the tests. It turned out we can switch to loadfile because right now they are in one file by mistake but that is likely to change.

I agree there might be a conflict with #18 but on the other hand that seems overly complex and no one is working on it :P

@boxed
Copy link
Author

boxed commented Nov 9, 2018

Btw, if this ticket is implemented, it should start by distributing the locked jobs so as to maximize parallelization. I'm looking at a run with --dist=loadfile right now that is super slow at the end because just one worker is running. This would be easy to fix with this ticket.

@nicoddemus
Copy link
Member

Glad to know that loadfile is enough for your needs. Agree that we should send all jobs bound to a worker immediately.

@boxed
Copy link
Author

boxed commented Nov 9, 2018

Actually I spoke too soon. Loadfile has other problems so we'll have to just exclude some stuff from the xdist run totally :( I'll still be an improve but this feature would be much nicer.

@nicoddemus
Copy link
Member

nicoddemus commented Nov 9, 2018

I'm thinking that we should implement the proposal in #19 (comment) to at least allow some meta-data to travel from worker to master; this would open the possibility of implementing more complex custom schedulers, such as the one you propose.

I'm talking about the pytest_xdist_collect_modify_meta hook and allow schedulers to access the dict meta-data.

@nicoddemus
Copy link
Member

Seems like this can be accomplished by using the xdist_group mark and using loadgroup: you just need to be careful and group all the tests that require the authentication fixture in the same group.

Closing for now, we can reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants