Skip to content

fix issue #1618 by considering plugin args first #1673

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

**Changes**

*
* fix (`#1618`_): properly consider explicitly blocked plugins
Copy link
Member

Choose a reason for hiding this comment

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

Could explain this in more detail here?

Copy link
Member

Choose a reason for hiding this comment

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

I fear this is too "pytest-internal-specific" and users won't really know what's going on... suggestion:

Fix #1618: consider --plugins (-p) option before loading installed plugins, so it can be used to disable
plugins with problems or incorrectly installed (by using -p no:<plugin name>).

Copy link
Member

Choose a reason for hiding this comment

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

This is the first time I understand what this PR really solves 😆 👍

by considering pluginargs before setuptools plugin
(which avoids calling addopts from a plugin that was asked to be disabled)

*

Expand Down
4 changes: 2 additions & 2 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def import_plugin(self, modname):
# basename for historic purposes but must be imported with the
# _pytest prefix.
assert isinstance(modname, str)
if self.get_plugin(modname) is not None:
if self.get_plugin(modname) is not None or self.is_blocked(modname):
return
if modname in builtin_plugins:
importspec = "_pytest." + modname
Expand Down Expand Up @@ -894,9 +894,9 @@ def fromdictargs(cls, option_dict, args):
""" constructor useable for subprocesses. """
config = get_config()
config.option.__dict__.update(option_dict)
config.parse(args, addopts=False)
for x in config.option.plugins:
config.pluginmanager.consider_pluginarg(x)
config.parse(args, addopts=False)
return config

def _processopt(self, opt):
Expand Down
23 changes: 21 additions & 2 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_confcutdir(self, testdir):
""")
result = testdir.inline_run("--confcutdir=.")
assert result.ret == 0

class TestConfigCmdlineParsing:
def test_parsing_again_fails(self, testdir):
config = testdir.parseconfig()
Expand Down Expand Up @@ -352,6 +352,25 @@ def test_inifilename(self, tmpdir):
assert config.inicfg.get('name') == 'value'
assert config.inicfg.get('should_not_be_set') is None

@pytest.mark.issue1618
def test_consider_plugin(self, testdir):
Copy link
Member

Choose a reason for hiding this comment

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

Please mention #1618 on the docstring.

Copy link
Member

Choose a reason for hiding this comment

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

Also, when creating commit messages you can add a line "Fix #1618" so it closes the issue automatically when merged.

pytest.importorskip('xdist')
Copy link
Member

Choose a reason for hiding this comment

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

This test failed in CI, but only on xdist tox environments: I think we should run this in all environments because while I understand this was initially reported and diagnosed with xdist, the problem is general to pytest.

Copy link
Member Author

Choose a reason for hiding this comment

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

the test itself requires xdist, since the bug is triggered in config.from_dictargs
its simply impossible to test it with normal pytest

Copy link
Member Author

Choose a reason for hiding this comment

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

the more interesting question is - why do these fail on ci, it works in my local test :/ i wonder where my environment is different

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure? I'm think I tested this fix on a virtual environment without xdist...

Oh yes, I remember, I got the same problem and tested your fix just by running py.test, without passing -n1. If it should be run in both environments, I guess we should parametrize this then.

Copy link
Member Author

Choose a reason for hiding this comment

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

i am certain that xdist is currently the only thing triggering the behavior

the problem in question is the worker process ignoring the 'no:foo' plugin spec

Copy link
Member

Choose a reason for hiding this comment

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

i am certain that xdist is currently the only thing triggering the behavior

Something is wrong then... just tested on a fresh environment, without any plugins.

master

λ py.test test_foo.py -p no:plugin
Traceback (most recent call last):
...
  File "C:\Users\bruno\addopts-order\src\plugin.py", line 1, in <module>
    raise ValueError
ValueError

RonnyPfannschmidt:fix-1618

λ py.test test_foo.py -p no:plugin
============================= test session starts =============================
platform win32 -- Python 2.7.11, pytest-2.10.0.dev1, py-1.4.31, pluggy-0.3.1
rootdir: C:\Users\bruno\addopts-order\src, inifile:
collected 1 items

test_foo.py .

========================== 1 passed in 0.01 seconds =========================

That was on Python 2.7.

the more interesting question is - why do these fail on ci, it works in my local test :/ i wonder where my environment is different

Should be res.ret instead of res.res, not sure why that passes for you.

I also executed your test on my new environment, and it passes if I don't have xdist and don't pass -n1 (also changing to res.ret):

import pytest

pytest_plugins = ['pytester']

def test_consider_plugin(testdir):
#    pytest.importorskip('xdist')
    print (testdir)
    testdir.makepyfile(conftest="""
            pytest_plugins = ['plugin']
        """,
        plugin="""
            raise ImportError
        """,
        test_foo="""
            def test():
                pass
        """,
    )
    res = testdir.inline_run(
        #'-n1',
        '-p', 'no:plugin')
    assert res.ret == 0
λ py.test test_ronny.py
============================= test session starts =============================
platform win32 -- Python 2.7.11, pytest-2.10.0.dev1, py-1.4.31, pluggy-0.3.1
rootdir: C:\Users\bruno\addopts-order\src, inifile:
collected 1 items

test_ronny.py .

========================== 1 passed in 0.10 seconds ===========================

The same test fails on master as expected:

ImportError: Error importing plugin "plugin"

So I'm guessing there is something weird with your local environment.

print (testdir)
testdir.makepyfile(conftest="""
pytest_plugins = ['plugin']
""",
plugin="""
raise ImportError
""",
test_foo="""
def test():
pass
""",
)
res = testdir.inline_run(
'-n1',
'-p', 'no:plugin')
assert res.res == 0

def test_options_on_small_file_do_not_blow_up(testdir):
def runfiletest(opts):
Expand Down Expand Up @@ -671,4 +690,4 @@ def test_multiple_options(pytestconfig):
"ini2:url=/tmp/user2?a=b&d=e",
"ini3:True",
"ini4:False"
])
])