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

fix issue #1618 by considering plugin args first #1673

Closed

Conversation

RonnyPfannschmidt
Copy link
Member

additionally prevent unnecessary importation of blocked plugins

@@ -352,6 +352,24 @@ def test_inifilename(self, tmpdir):
assert config.inicfg.get('name') == 'value'
assert config.inicfg.get('should_not_be_set') is None

def test_consider_plugin(self, testdir):
pytest.importorskip('xdist')
print testdir
Copy link
Member

Choose a reason for hiding this comment

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

Seems like that shouldn't be here

Copy link
Member

Choose a reason for hiding this comment

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

That's what broke all Py3 builds. 😁

@@ -352,6 +352,24 @@ def test_inifilename(self, tmpdir):
assert config.inicfg.get('name') == 'value'
assert config.inicfg.get('should_not_be_set') is None

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.

@coveralls
Copy link

coveralls commented Jun 27, 2016

Coverage Status

Coverage remained the same at 92.09% when pulling 5f61109 on RonnyPfannschmidt:fix-1618 into ccd395f on pytest-dev:features.

@coveralls
Copy link

coveralls commented Jun 27, 2016

Coverage Status

Coverage remained the same at 92.09% when pulling 5f61109 on RonnyPfannschmidt:fix-1618 into ccd395f on pytest-dev:features.

@RonnyPfannschmidt
Copy link
Member Author

@The-Compiler @nicoddemus take alook?

@@ -3,7 +3,7 @@

**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 😆 👍

@nicoddemus
Copy link
Member

Other than my minor comment this looks 👍 to me! 😁

@coveralls
Copy link

coveralls commented Jun 30, 2016

Coverage Status

Coverage remained the same at 92.09% when pulling 9e19507 on RonnyPfannschmidt:fix-1618 into ccd395f on pytest-dev:features.

pass
""",
)
testdir.inline_run(
Copy link
Member

@nicoddemus nicoddemus Jul 6, 2016

Choose a reason for hiding this comment

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

This should verify that the test runs OK, so -p could effectively disable the problematic plugin. As it stands, the return of inline_run is just being ignored.

@nicoddemus
Copy link
Member

I tried your branch with a small example similar to the test, this is what I get:

$ py.test test_f.py
_______________________ ERROR collecting tmp/test_f.py ________________________
..\_pytest\python.py:373: in fget
    return self._obj
E   AttributeError: 'Module' object has no attribute '_obj'

During handling of the above exception, another exception occurred:
plugin.py:1: in <module>
    raise ValueError
E   ValueError
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.14 seconds ===========================

(Note I'm not using -p no:plugin).

On master the same command line looks better:

$ py.test test_f.py
=================================== ERRORS ====================================
_______________________ ERROR collecting tmp/test_f.py ________________________
plugin.py:1: in <module>
    raise ValueError
E   ValueError
=========================== 1 error in 0.01 seconds ===========================

Could you take a look at that?

FWIW passing -p no:plugin on your branch works as expected: 👍

$ py.test test_f.py -p no:plugin
============================= test session starts =============================
platform win32 -- Python 3.5.0, pytest-2.10.0.dev1, py-1.4.31, pluggy-0.3.1
rootdir: X:\pytest, inifile: tox.ini
plugins: hypothesis-3.1.0, xdist-1.14
collected 1 items

test_f.py .

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

@RonnyPfannschmidt
Copy link
Member Author

Can you show the file content?

@nicoddemus
Copy link
Member

Sorry I don't have them with me right now, but IIRC:

# conftest.py
pytest_plugins = ['plugin']

# plugin.py
raise ValueError

# test_f.py
def test():
    pass

@coveralls
Copy link

coveralls commented Jul 6, 2016

Coverage Status

Coverage increased (+0.005%) to 92.095% when pulling 2592c26 on RonnyPfannschmidt:fix-1618 into ccd395f on pytest-dev:features.

@@ -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):
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.

@nicoddemus
Copy link
Member

Any news here @RonnyPfannschmidt?

@RonnyPfannschmidt
Copy link
Member Author

@nicoddemus didnt get to touch this one today, hope to get at it in the afternoon

@RonnyPfannschmidt
Copy link
Member Author

closing this one, the approach i picked is problematic and configuration construction is "tricky"
in order to approach this in a comprehensible manner, the config object initialization has tobe reworked

@RonnyPfannschmidt RonnyPfannschmidt deleted the fix-1618 branch June 29, 2021 14:04
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