-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Extend Config to override ini values programmatically #3311
Comments
GitMate.io thinks possibly related issues are #204 (allow to dynamically modify all ini-values from plugins), #3103 (UsageError raised when specifying config override options followed by test path(s)), #2039 (Call "--collect-only" programmatically ), #2544 (Run tests truly programmatically), and #3050 (deprecate pytest.config). |
Hi @acerv, Changing ini options on the fly feels brittle because you never know when another plugin is actually reading the value of a ini option, which might be earlier than you expect (or even change from one version to another). For example a certain option of Having said all that, IIUC in your use case all the parties involved are under your control, so you probably can get away with it. I suggest a couple of options:
I would be a little cautious about adding a new |
Thank you very much for your reply. The system is still under evaluation, but to me, I don't see many options but using the _inicache, which is scaring me a bit because of side-effects on the system for a pytest update. The For now I can say that the problem release on a particular case, which is the |
Indeed this will be a problem, I'm afraid. Perhaps @RonnyPfannschmidt can share his opinion here? |
i would suggest to put everything that configures the values and data elements into a singe plugin object, which can be looked up by the other plugins just fine from the config that way you have a custom object that provides the values you need exactly in the way you need without needing to mess with any of pytests config values |
Thanks @RonnyPfannschmidt for your suggestion. That was a plan, but I figured out that placing all configurations, which are mostly specific for other plugins, in one since configuration plugin causes major issues and a sort of "circular dependency" between plugins. I would like to have many plugins placing their own ini configuration inside pytest, and then one single plugin overriding these configurations if (and only if) these values have been fetched from a DB by using the This is done at the moment, by using the following code:
|
as far as i understood, that plugin need to be aware of all configuration, so i should bear the responsibility for all of those as well, that way the configuration values are managed by a singular plugin you can then use as source of truth of the other plugins with what i know so far i believe anything else will be more hackish and more fragile |
Each ini value is well documented and exposed to the users. Then the The idea is that configuring the DB correctly (with the same key name of the ini values) the plugin automatically updates these values, overriding the ones coming from pytest.ini. |
After a deeper analysis, I guess the solution provided by @nicoddemus using the Still, I need to figure out how to handle the execution of a particular operation using fixtures inside the I also thought that it's maybe possible to create a custom test, which is going to be executed before all the other tests and using a specific fixture to do the trick. What do you think about it? |
Can you provide more details of what you have to do there? How things work now, no fixture will have been created at this point yet: fixtures are created when tests request them.
It is not clear to me what that test would do, set some global variable which would then be accessed during |
Thank you @nicoddemus . After a deeper analysis and implemented the One limitation I found in the pytest execution, is the number of possible ini files loaded in on session.
In this way I can generate only setup.cfg, keeping pytest.ini unchanged. Is already possible to enable this feature in some kind of way, or I need to implement it with a plugin? Thanks |
Hi @acerv, Currently pytest only supports loading from a single ini file and I don't think there are hooks in place to make it load more than one file. But if you plan to use a tool to generate a |
@nicoddemus thank you very much for your support, the trick worked perfectly! |
I'm afraid reading configuration from |
Closing this issue because there's a good alternative to the proposal and issue is inactive. |
I actually think this issue should be re-opened. in our case we are using a project that is heavily use pytest but most of the project configuration lays in for example, if i'm writing a plugin that uses another plugin, and i want to be able to change the options passed to this plugin there is no way i cant do it with regular |
Hello, I'm trying to find a way to override custom ini values defined inside pytest.ini.
My scenario is the following: I have a custom option called
--resource-enable
which is implemented inside a plugin called "resources.py". If--resource-enable
is used, my plugin fetch the configuration from a DB (dict
type) and it has to override the pytest.ini variables defined inside the other plugins which expose the fixtures.The system is needed in order to accomplish a complex automation scenario using Jenkins and some other proprietary tools.
In short:
At the moment, there are no other ways but using
config.addinivalue_line
, but most of my ini items have the simplekey=value
form. Aconfig.addinivalue
would be really useful in this case.Thanks,
Andrea
The text was updated successfully, but these errors were encountered: