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

deprecate pytest_plugins in non-top-level conftest #3230

Merged
merged 2 commits into from
Mar 21, 2018

Conversation

brianmaissy
Copy link
Contributor

Fixes #3084

@brianmaissy brianmaissy changed the base branch from master to features February 16, 2018 14:52
@coveralls
Copy link

coveralls commented Feb 16, 2018

Coverage Status

Coverage increased (+0.04%) to 92.701% when pulling 8035f6c on brianmaissy:features into d6ddeb3 on pytest-dev:features.

@@ -364,6 +364,9 @@ def _importconftest(self, conftestpath):
_ensure_removed_sysmodule(conftestpath.purebasename)
try:
mod = conftestpath.pyimport()
if hasattr(mod, 'pytest_plugins') and len(self._conftest_plugins) > 0:
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
self._warn(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST)
Copy link
Member

Choose a reason for hiding this comment

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

we should include the relative module location in the error message

i'd appreciate if warnings.warn was used there, but i can understand leaving as is if it seems hard/very time consuming to enable it, i dont what to turn this into a time sink for you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not a problem at all, I was just worried about its visibility

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -50,3 +50,9 @@ class RemovedInPytest4Warning(DeprecationWarning):
"Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.\n"
"Please use Metafunc.parametrize instead."
)

PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = (
Copy link
Member

Choose a reason for hiding this comment

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

in case its viable to use warnings.warn, lets please make this a warning object.
otherwise lets have a small todo comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -364,6 +364,9 @@ def _importconftest(self, conftestpath):
_ensure_removed_sysmodule(conftestpath.purebasename)
try:
mod = conftestpath.pyimport()
if hasattr(mod, 'pytest_plugins') and len(self._conftest_plugins) > 0:
Copy link
Member

Choose a reason for hiding this comment

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

@RonnyPfannschmidt is using len(self._conftest_plugins) > 0 to identify the root conftest the correct approach, regardless where the collection started? Just making sure.

Copy link
Member

Choose a reason for hiding this comment

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

its not, i'll take a while to identify the right approach for the initial contests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you give an example of a situation in which the top level conftest won't be the first collected? I wasn't able to find one.

Copy link
Member

Choose a reason for hiding this comment

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

@brianmaissy the situation i wondering about is where there is no toplevel conftest to begin with

Copy link
Contributor Author

@brianmaissy brianmaissy Feb 17, 2018

Choose a reason for hiding this comment

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

Ah I see. Any conftest whose directory is not an ancestor of all collected tests. That would involve keeping track of which conftests used pytest_plugins during collection, and then determining it after collection is finished. Seems complicated.

Or we could say that only a conftest located in the rootdir can use pytest_plugins. But that might be too restrictive.

Copy link
Contributor Author

@brianmaissy brianmaissy Feb 17, 2018

Choose a reason for hiding this comment

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

So for sure my implementation yields false negatives. You could also say it yields false positives if you consider this directory structure valid:

a/
  conftest.py (defining pytest_plugins)
  b/
    conftest.py (defining pytest_plugins)
    test_it.py

Copy link
Member

Choose a reason for hiding this comment

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

in order to sort it out i believe a check if pytest is configured fits

early conftests are imported and used while the pytest_configure step did not yet happen,
later conftests are imported as part of collection after pytest_configure did happen

@brianmaissy brianmaissy force-pushed the features branch 5 times, most recently from 8d8bcac to 6c25af4 Compare February 20, 2018 23:27
@brianmaissy
Copy link
Contributor Author

Haha finally got that failing test! Today I learned pypy is picky about source file encoding

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Sorry but I just realized that we need to add a more detailed explanation to the docs, one of the first things users will do when they see this warning is to search the docs for an explanation. Perhaps a note in the section Requiring/Loading plugins in a test module or conftest file of writing_plugins.rst would be best?

@brianmaissy
Copy link
Contributor Author

Yeah sounds good

@brianmaissy
Copy link
Contributor Author

done, sorry for the delay

@nicoddemus
Copy link
Member

nicoddemus commented Mar 12, 2018

Thanks @brianmaissy for following up with the PR!

I fixed a small typo, as soon as CI passes we can merge this. I just now noticed that we still need @RonnyPfannschmidt's approval, let's wait for it then. 😁

@nicoddemus
Copy link
Member

@RonnyPfannschmidt gentle ping. 😁

@RonnyPfannschmidt RonnyPfannschmidt merged commit add5ce0 into pytest-dev:features Mar 21, 2018
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