-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Plugin fixtures with leading underscore ignored outside project defining them #3366
Comments
GitMate.io thinks possibly related issues are #177 (Test functions with leading underscores ignored), #2793 (Overwriting a fixture in a plugin), #1480 (py.test ignores exceptions in fixtures), #1082 (Duplicate fixtures in complex projects), and #519 (fixture scope is ignored when using metafunc.parametrize()). |
Hi @kohr-h, sorry for the delay. Weird, I don't see anything about excluding fixtures prefixed with Line 1093 in e012dbe
@RonnyPfannschmidt do you have any insights here? |
Thanks for the answer @nicoddemus. Just to make sure that my description makes sense: Let's say I have two source trees entry_points={'pytest11': ['projectX_plugins = projectX.util.pytest_plugins']} where Now let's consider two scenarios:
Both projects have been installed with
So it seems like by default, fixtures with leading underscore are considered "foreign" or "internal" when coming from a plugin and are omitted. As I write above, I find this pretty useful, and my question is whether I can rely on this as a feature. |
no idea either ^^ |
@kohr-h thanks for the detailed follow up, but unfortunately I have been unable to reproduce your problem. Here's what I did: Created a dummy package which contains two fixtures and a # myplugin.py
import pytest
@pytest.fixture
def visible():
return 1
@pytest.fixture
def _invisible():
return 2
# setup.py
from setuptools import setup
def main():
setup(
name='myplugin',
description='',
long_description='',
url='http://myplugin.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
author='someone',
entry_points={'pytest11': ['myplugin = myplugin']},
py_modules=['myplugin'],
zip_safe=False,
)
if __name__ == '__main__':
main() I installed this package into a virtual environment in def test_a(visible):
assert visible == 1
def test_b(_invisible):
assert _invisible == 2 Output:
We can see that Can you create a small reproducible example that shows your problem? It might be related to something else or some detail I'm missing. Thanks! |
I was just cooking up a minimal example to see the tests failing with two repos and two separate plugins and tests that involve the respective other fixtures. However, if you take your setup and run So the real issue is in the |
Oh OK, that explains it. 😅 Here's the code responsible for that: Lines 1069 to 1070 in 0024b71
So fixtures with leading underscores will show up if you pass The commit at that line is 20849a4 and reads:
That change seems to have been introduced in 2.3.0 based on the tags, but I can't find anything related to that in the changelog entries or the issue tracker. @RonnyPfannschmidt does this ring a bell to you? |
nope |
Thanks for the help @nicoddemus. |
Under my version of pytest, which is 3.5.0, fixtures that are part of a
setuptools
-registered plugin (using thepytest11
entry point) whose names begin with an underscore, are being ignored outside the project that define them.I find this pretty useful, since it allows me to implement fixtures that are global to my project but don't interfere with other projects' fixtures.
However, I don't find this documented anywhere. Is it intended behavior?
The text was updated successfully, but these errors were encountered: