Replies: 2 comments 3 replies
-
Hi @silbe, I think the solution is a matter of taste, but I would make the StashKey part of the public API of the plugin, and the other plugins can access the value in the stash using the key directly. |
Beta Was this translation helpful? Give feedback.
-
Alternatively you can instruct users to only import your plugin locally inside functions and methods which need to access the key. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've written a plugin that streams test results into a file and provides fixtures that can be used by both fixtures and tests to include structured data in the test results file. The fixtures store the data on the stash of the Item. A
pytest_runtest_makereport()
hook copies (a reference to) the data from the Item stash to the Report stash. In thepytest_make_collect_report()
both the test result and the structured data on the Report stash are used to output the test results.This works fine so far. Now I'd like to factor out the (pretty generic) structured data fixtures into a separate plugin so they can be used independently of the specific output format of the test result plugin. If I were using only fixtures, that would be pretty easy; I'd just request the fixtures of the structured data plugin from the fixtures in the test result plugin and be done with it. However I need to access the data from within hooks, not fixtures.
I have a couple of ideas how to achieve that but none of them feels like a good solution:
pytest.StashKey
, use a fixed string and let the other plugins hard-code that string.StashKey
on the plugin reference. (Does using the plugin manager to access functions or variables in a plugin even work?)Is there a better approach?
Beta Was this translation helpful? Give feedback.
All reactions