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

Make passing plugins as str objects a more obvious failure #860

Merged

Conversation

nicoddemus
Copy link
Member

See #855

CC @xmo-odoo

@@ -80,6 +80,9 @@ def _prepareconfig(args=None, plugins=None):
try:
if plugins:
for plugin in plugins:
if isinstance(plugin, str):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe warn in case of unicode strings as well? Not sure how pytest handles the 2/3 split though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using py.builtin._basestring IIRC

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks! 😄

@flub
Copy link
Member

flub commented Jul 19, 2015

I think it would be better to do this fix in pluggy rather then in py.test to be honest.

Also, is something like not isinstance(plugin, (types.ModuleType, types.ClassType, types.InstanceType)) not more correct for this check?

@flub
Copy link
Member

flub commented Jul 19, 2015

Hum, maybe the isinstance I suggest is not really in the spirit of ducktyping. And hence the generic approach in pluggy not so great. Furthermore a plugin could provide no hooks but only some fixtures in which case the generic approach in pluggy is also not so great. So maybe my previous comment is wrong and this PR is the right approach anyway.

@xmo-odoo
Copy link

Also, is something like not isinstance(plugin, (types.ModuleType, types.ClassType, types.InstanceType)) not more correct for this check?

Well you'd also need to add object to it as any arbitrary instance could be a plugin, but then you face the issue that isinstance("foo", object) is True.

Furthermore a plugin could provide no hooks but only some fixtures in which case the generic approach in pluggy is also not so great.

It just happens that my original use case was indeed a plugin which only provided fixtures, no hooks. And my feature request was about excluding strings: I had thought that since -p takes a "string" designator for plugins it could also work for the plugins argument. It is an ID10T error, but one which I think has at least a bit of logic threaded through it.

@RonnyPfannschmidt
Copy link
Member

random thought, could we just consider strings in the same manner we consider the -p option ?

@xmo-odoo
Copy link

That would certainly be an alternative.

@nicoddemus
Copy link
Member Author

Good idea @RonnyPfannschmidt, updated the PR to interpret strings as module names instead. 😄

@nicoddemus nicoddemus force-pushed the warn-plugins-as-str-main branch 2 times, most recently from b669445 to 449cfcd Compare July 23, 2015 23:48
@RonnyPfannschmidt
Copy link
Member

+1

nicoddemus added a commit that referenced this pull request Jul 24, 2015
Make passing plugins as str objects a more obvious failure
@nicoddemus nicoddemus merged commit 91e8e59 into pytest-dev:pytest-2.7 Jul 24, 2015
@nicoddemus nicoddemus deleted the warn-plugins-as-str-main branch July 24, 2015 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants