sprad
sprad

Reputation: 343

Storing global configuration data in a pytest/xdist framework

I'm building a test framework using python + pytest + xdist + selenium grid. This framework needs to talk to a pre-existing custom logging system. As part of this logging process, I need to submit API calls to: set up each new test run, set up test cases within those test runs, and log strings and screenshots to those test cases.

The first step is to set up a new test run, and the API call for that returns (among other things) a Test Run ID. I need to keep this ID available for all test cases to read. I'd like to just stick it in a global variable somewhere, but running my tests with xdist causes the framework to lose track of the value.

I've tried:

At this point, I'm considering writing it to a temp file, but that seems primitive, and I think I'm overlooking a better solution. What's the most correct, pytest-style way to store and access global data across multiple xdist threads?

Upvotes: 1

Views: 1239

Answers (2)

Ben
Ben

Reputation: 104

Can you try config.cache E.g. -

request.config.cache.set('run_id', run_id)

refer documention

Upvotes: 1

Jonnyboy
Jonnyboy

Reputation: 136

Might be worth looking into Proboscis, as it allows specific test dependencies and could be a possible solution.

Upvotes: 0

Related Questions