Comments (10)
@tgoodlet sounds potentially practical, but also not something we can expose in pytest (due to lack of plugin dependency maangement)
from pluggy.
Nothing against the proposal, I'm a bit curious about the use case: the temporary plugin registration is for testing, or to be used during production?
from pluggy.
@RonnyPfannschmidt oh yeah? Is there a way we can fix that?
@nicoddemus I was thinking both. It allows a plugin creator to overload hooks temporarily. If a hook is called multiple times under different contexts it may come in handy.
One example from pysipp
is only on the first hook call do you want the netplug
plugin registered (it allocates random ports from the system for SIPp to use as default arguments) for the first call to pysipp_conf_scen_protocol()
but later configuration calls should not mutate these port selections again. Having the convenience of doing this with a collection of plugins in a with
block is syntactically nice imo.
from pluggy.
Thanks for the use case @goodboy !
I think it is perfectly fine to add this. 😁
I wonder though, we might implement this functionality using just PluginManager.register
:
with pm.register(plugin):
# plugin will be unregistered after the end of the block
I think it is pretty readable, backward compatible and we don't need to add a new API. It doesn't let you register multiple plugins in a single call, unless we change the PluginManager.register
signature to support multiple plugins, which is also possible & backward compatible.
from pluggy.
@nicoddemus to make this backwards compat won't we need to still return the plugin name?
If so then I'm not sure how we can use PluginManager.register
unless we return a new type (of course supporting __enter__
and __exit__
) where the returned value is str
-like?
I guess it's possible but seems a bit confusing and messy to implement.
from pluggy.
We can declare a single Plugin that depends in more plugins, but AS things are, pluggy is unaware of dependent plugins
from pluggy.
to make this backwards compat won't we need to still return the plugin name?
Oh I didn't realize we returned the plugin name, I assumed we returned None
.
Scratch that idea then, it would be too complicated to support it.
from pluggy.
@nicoddemus @hpk42 i do wonder if it would make sense to change the registration api and do major releases of pluggy/pytest
from pluggy.
You mean to no longer return the plugin name from register
?
from pluggy.
@nicoddemus that would be one example, before i propose an actual api change i want to survey use-cases better
also we do have many internals that are scarry and di things the messy way (blocking plugins, registering plugins and naming plugins are all interspersed in a "fun" dictionary that simply makes a mess
from pluggy.
Related Issues (20)
- Avoid erroring from tracing HOT 4
- Drop Python 3.7
- Export our typing HOT 2
- multi hook registration does not unregister HOT 6
- Can plugins be executed concurrently? HOT 3
- RFE: is it possible to start making github releases?🤔 HOT 3
- pytest won't run root conftest.py's pytest_configure in special circumstances HOT 2
- Rename misleading function name `PluggyManager.load_setuptools_entrypoints` HOT 3
- Issue with ordering of hooks HOT 2
- Question about default values in hook implementation HOT 1
- discussion: pluggy speedup by using 'codegen' HOT 7
- Is it possible to override an existing hook with a HookCaller class?
- pluggy loads disabled pytest plugins HOT 5
- Warn when old-style hookwrapper raises during teardown
- Add python-lsp-server to downstream tests
- Troubles to understand the new updates on Pluggy HOT 11
- Bug: Pluggy 1.4 searches all home dirs for __init__.py HOT 2
- Possible to tell which hook answered a call? HOT 1
- load_setuptools_entrypoints messing up with rpath HOT 2
- How to get in touch regarding a security concern HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pluggy.