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

2021.4.29: Unable to run tests (AttributeError: module 'pytest' has no attribute 'helpers') #10

Closed
dvzrv opened this issue Jun 17, 2021 · 6 comments

Comments

@dvzrv
Copy link

dvzrv commented Jun 17, 2021

Hi! When packaging 2021.4.29 I attempted to run the tests. Unfortunately eight out of nine fail due to the error in the issue title.

After python setup.py build I install the package to a temporary location, so that it may be picked up by pytest (by modifying $PYTHONPATH before running pytest).

============================= test session starts ==============================
platform linux -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python
cachedir: .pytest_cache
rootdir: /build/python-pytest-helpers-namespace/src/python-pytest-helpers-namespace-2021.4.29
plugins: helpers-namespace-2021.4.29
collecting ... collected 9 items

tests/test_helpers_namespace.py::test_namespace FAILED                   [ 11%]
tests/test_helpers_namespace.py::test_nested_namespace FAILED            [ 22%]
tests/test_helpers_namespace.py::test_unregistered_namespace FAILED      [ 33%]
tests/test_helpers_namespace.py::test_namespace_override FAILED          [ 44%]
tests/test_helpers_namespace.py::test_namespace_override_2 FAILED        [ 55%]
tests/test_helpers_namespace.py::test_helper_override FAILED             [ 66%]
tests/test_helpers_namespace.py::test_helper_as_regular_function FAILED  [ 77%]
tests/test_helpers_namespace.py::test_helper_with_custom_name FAILED     [ 88%]
tests/test_helpers_namespace.py::test_helper_contains_method PASSED      [100%]

=================================== FAILURES ===================================
________________________________ test_namespace ________________________________

testdir = <Testdir local('/tmp/pytest-of-builduser/pytest-0/test_namespace0')>

    def test_namespace(testdir):
        testdir.makeconftest(
            """
            import pytest
    
            @pytest.helpers.register
            def foo(bar):
                return bar
            """
        )
    
        testdir.makepyfile(
            """
            import pytest
    
            def test_helpers():
                assert pytest.helpers.foo(True) is True
                print('PASSED')
        """
        )
    
        result = testdir.runpytest_subprocess("-s")
    
        # fnmatch_lines does an assertion internally
>       result.stdout.fnmatch_lines(
            [
                "test_namespace.py PASSED",
            ]
        )
E       Failed: remains unmatched: 'test_namespace.py PASSED'

/build/python-pytest-helpers-namespace/src/python-pytest-helpers-namespace-2021.4.29/tests/test_helpers_namespace.py:37: Failed
----------------------------- Captured stdout call -----------------------------
running: /usr/bin/python -mpytest --basetemp=/tmp/pytest-of-builduser/pytest-0/test_namespace0/runpytest-0 -s
     in: /tmp/pytest-of-builduser/pytest-0/test_namespace0
----------------------------- Captured stderr call -----------------------------
ImportError while loading conftest '/tmp/pytest-of-builduser/pytest-0/test_namespace0/conftest.py'.
conftest.py:3: in <module>
    @pytest.helpers.register
E   AttributeError: module 'pytest' has no attribute 'helpers'
____________________________ test_nested_namespace _____________________________

testdir = <Testdir local('/tmp/pytest-of-builduser/pytest-0/test_nested_namespace0')>

    def test_nested_namespace(testdir):
        testdir.makeconftest(
            """
            import pytest
    
            @pytest.helpers.foo.bar.register
            def foo(bar):
                return bar
            """
        )
    
        testdir.makepyfile(
            """
            import pytest
    
            def test_helpers():
                assert pytest.helpers.foo.bar.foo(True) is True
                print('PASSED')
        """
        )
    
        result = testdir.runpytest_subprocess("-s")
    
        # fnmatch_lines does an assertion internally
>       result.stdout.fnmatch_lines(
            [
                "test_nested_namespace.py PASSED",
            ]
        )
E       Failed: remains unmatched: 'test_nested_namespace.py PASSED'

/build/python-pytest-helpers-namespace/src/python-pytest-helpers-namespace-2021.4.29/tests/test_helpers_namespace.py:71: Failed
----------------------------- Captured stdout call -----------------------------
running: /usr/bin/python -mpytest --basetemp=/tmp/pytest-of-builduser/pytest-0/test_nested_namespace0/runpytest-0 -s
     in: /tmp/pytest-of-builduser/pytest-0/test_nested_namespace0
----------------------------- Captured stderr call -----------------------------
ImportError while loading conftest '/tmp/pytest-of-builduser/pytest-0/test_nested_namespace0/conftest.py'.
conftest.py:3: in <module>
    @pytest.helpers.foo.bar.register
E   AttributeError: module 'pytest' has no attribute 'helpers'
_________________________ test_unregistered_namespace __________________________

testdir = <Testdir local('/tmp/pytest-of-builduser/pytest-0/test_unregistered_namespace0')>

    def test_unregistered_namespace(testdir):
        testdir.makepyfile(
            """
            import pytest
    
            def test_helpers():
                with pytest.raises(RuntimeError) as exc:
                    assert pytest.helpers.foo(True) is True
                assert 'The helper being called was not registred' in str(exc)
                print('PASSED')
        """
        )
    
        result = testdir.runpytest_subprocess("-s")
    
        # fnmatch_lines does an assertion internally
>       result.stdout.fnmatch_lines(
            [
                "test_unregistered_namespace.py PASSED",
            ]
        )
E       Failed: nomatch: 'test_unregistered_namespace.py PASSED'
E           and: '============================= test session starts =============================='
E           and: 'platform linux -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1'
E           and: 'rootdir: /tmp/pytest-of-builduser/pytest-0/test_unregistered_namespace0'
E           and: 'collected 1 item'
E           and: ''
E           and: 'test_unregistered_namespace.py F'
E           and: ''
E           and: '=================================== FAILURES ==================================='
E           and: '_________________________________ test_helpers _________________________________'
E           and: ''
E           and: '    def test_helpers():'
E           and: '        with pytest.raises(RuntimeError) as exc:'
E           and: '>           assert pytest.helpers.foo(True) is True'
E           and: "E           AttributeError: module 'pytest' has no attribute 'helpers'"
E           and: ''
E           and: 'test_unregistered_namespace.py:5: AttributeError'
E           and: '=========================== short test summary info ============================'
E           and: 'FAILED test_unregistered_namespace.py::test_helpers - AttributeError: module ...'
E           and: '============================== 1 failed in 0.01s ==============================='
E       remains unmatched: 'test_unregistered_namespace.py PASSED'

/build/python-pytest-helpers-namespace/src/python-pytest-helpers-namespace-2021.4.29/tests/test_helpers_namespace.py:97: Failed
----------------------------- Captured stdout call -----------------------------
running: /usr/bin/python -mpytest --basetemp=/tmp/pytest-of-builduser/pytest-0/test_unregistered_namespace0/runpytest-0 -s
     in: /tmp/pytest-of-builduser/pytest-0/test_unregistered_namespace0
============================= test session starts ==============================
platform linux -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/pytest-of-builduser/pytest-0/test_unregistered_namespace0
collected 1 item

test_unregistered_namespace.py F

=================================== FAILURES ===================================
_________________________________ test_helpers _________________________________

    def test_helpers():
        with pytest.raises(RuntimeError) as exc:
>           assert pytest.helpers.foo(True) is True
E           AttributeError: module 'pytest' has no attribute 'helpers'

test_unregistered_namespace.py:5: AttributeError
=========================== short test summary info ============================
FAILED test_unregistered_namespace.py::test_helpers - AttributeError: module ...
============================== 1 failed in 0.01s ===============================
___________________________ test_namespace_override ____________________________

testdir = <Testdir local('/tmp/pytest-of-builduser/pytest-0/test_namespace_override0')>

    def test_namespace_override(testdir):
        testdir.makeconftest(
            """
            import pytest
    
            @pytest.helpers.foo.register
            def bar(bar):
                return bar
    
            @pytest.helpers.register
            def foo(bar):
                return bar
            """
        )
        testdir.makepyfile(
            """
            import pytest
    
            def test_helpers():
                with pytest.raises(RuntimeError) as exc:
                    assert pytest.helpers.foo(True) is True
                assert 'The helper being called was not registred' in str(exc)
                print('PASSED')
        """
        )
    
        result = testdir.runpytest_subprocess("-s")
    
        # fnmatch_lines does an assertion internally
>       result.stderr.fnmatch_lines(
            ["*RuntimeError: A helper function is already registered under the name: foo"]
        )
E       Failed: nomatch: '*RuntimeError: A helper function is already registered under the name: foo'
E           and: "ImportError while loading conftest '/tmp/pytest-of-builduser/pytest-0/test_namespace_override0/conftest.py'."
E           and: 'conftest.py:3: in <module>'
E           and: '    @pytest.helpers.foo.register'
E           and: "E   AttributeError: module 'pytest' has no attribute 'helpers'"
E       remains unmatched: '*RuntimeError: A helper function is already registered under the name: foo'

/build/python-pytest-helpers-namespace/src/python-pytest-helpers-namespace-2021.4.29/tests/test_helpers_namespace.py:136: Failed
----------------------------- Captured stdout call -----------------------------
running: /usr/bin/python -mpytest --basetemp=/tmp/pytest-of-builduser/pytest-0/test_namespace_override0/runpytest-0 -s
     in: /tmp/pytest-of-builduser/pytest-0/test_namespace_override0
----------------------------- Captured stderr call -----------------------------
ImportError while loading conftest '/tmp/pytest-of-builduser/pytest-0/test_namespace_override0/conftest.py'.
conftest.py:3: in <module>
    @pytest.helpers.foo.register
E   AttributeError: module 'pytest' has no attribute 'helpers'
__________________________ test_namespace_override_2 ___________________________

testdir = <Testdir local('/tmp/pytest-of-builduser/pytest-0/test_namespace_override_20')>

    def test_namespace_override_2(testdir):
        testdir.makeconftest(
            """
            import pytest
    
            @pytest.helpers.register
            def foo(bar):
                return bar
    
            @pytest.helpers.foo.register
            def bar(bar):
                return bar
            """
        )
        testdir.makepyfile(
            """
            import pytest
    
            def test_helpers():
                with pytest.raises(RuntimeError) as exc:
                    assert pytest.helpers.foo(True) is True
                assert 'The helper being called was not registred' in str(exc)
                print('PASSED')
        """
        )
    
        result = testdir.runpytest_subprocess("-s")
    
        # fnmatch_lines does an assertion internally
>       result.stderr.fnmatch_lines(
            ["*RuntimeError: A namespace is already registered under the name: bar"]
        )
E       Failed: nomatch: '*RuntimeError: A namespace is already registered under the name: bar'
E           and: "ImportError while loading conftest '/tmp/pytest-of-builduser/pytest-0/test_namespace_override_20/conftest.py'."
E           and: 'conftest.py:3: in <module>'
E           and: '    @pytest.helpers.register'
E           and: "E   AttributeError: module 'pytest' has no attribute 'helpers'"
E       remains unmatched: '*RuntimeError: A namespace is already registered under the name: bar'

/build/python-pytest-helpers-namespace/src/python-pytest-helpers-namespace-2021.4.29/tests/test_helpers_namespace.py:173: Failed
----------------------------- Captured stdout call -----------------------------
running: /usr/bin/python -mpytest --basetemp=/tmp/pytest-of-builduser/pytest-0/test_namespace_override_20/runpytest-0 -s
     in: /tmp/pytest-of-builduser/pytest-0/test_namespace_override_20
----------------------------- Captured stderr call -----------------------------
ImportError while loading conftest '/tmp/pytest-of-builduser/pytest-0/test_namespace_override_20/conftest.py'.
conftest.py:3: in <module>
    @pytest.helpers.register
E   AttributeError: module 'pytest' has no attribute 'helpers'
_____________________________ test_helper_override _____________________________

testdir = <Testdir local('/tmp/pytest-of-builduser/pytest-0/test_helper_override0')>

    def test_helper_override(testdir):
        testdir.makeconftest(
            """
            import pytest
    
            @pytest.helpers.register
            def foo(bar):
                return bar
    
            @pytest.helpers.register
            def foo(bar):
                return bar
            """
        )
        testdir.makepyfile(
            """
            import pytest
    
            def test_helpers():
                with pytest.raises(RuntimeError) as exc:
                    assert pytest.helpers.foo(True) is True
                assert 'The helper being called was not registred' in str(exc)
                print('PASSED')
        """
        )
    
        result = testdir.runpytest_subprocess("-s")
    
        # fnmatch_lines does an assertion internally
>       result.stderr.fnmatch_lines(
            ["*RuntimeError: A helper function is already registered under the name: foo"]
        )
E       Failed: nomatch: '*RuntimeError: A helper function is already registered under the name: foo'
E           and: "ImportError while loading conftest '/tmp/pytest-of-builduser/pytest-0/test_helper_override0/conftest.py'."
E           and: 'conftest.py:3: in <module>'
E           and: '    @pytest.helpers.register'
E           and: "E   AttributeError: module 'pytest' has no attribute 'helpers'"
E       remains unmatched: '*RuntimeError: A helper function is already registered under the name: foo'

/build/python-pytest-helpers-namespace/src/python-pytest-helpers-namespace-2021.4.29/tests/test_helpers_namespace.py:210: Failed
----------------------------- Captured stdout call -----------------------------
running: /usr/bin/python -mpytest --basetemp=/tmp/pytest-of-builduser/pytest-0/test_helper_override0/runpytest-0 -s
     in: /tmp/pytest-of-builduser/pytest-0/test_helper_override0
----------------------------- Captured stderr call -----------------------------
ImportError while loading conftest '/tmp/pytest-of-builduser/pytest-0/test_helper_override0/conftest.py'.
conftest.py:3: in <module>
    @pytest.helpers.register
E   AttributeError: module 'pytest' has no attribute 'helpers'
_______________________ test_helper_as_regular_function ________________________

testdir = <Testdir local('/tmp/pytest-of-builduser/pytest-0/test_helper_as_regular_function0')>

    def test_helper_as_regular_function(testdir):
        testdir.makepyfile(
            """
            import pytest
    
            @pytest.helpers.register
            def foo():
                return 'bar'
    
            def test_helpers():
                assert pytest.helpers.foo() == 'bar'
                assert foo() == 'bar'
                print('PASSED')
        """
        )
    
        result = testdir.runpytest_subprocess("-s")
    
        # fnmatch_lines does an assertion internally
>       result.stdout.fnmatch_lines(
            [
                "test_helper_as_regular_function.py PASSED",
            ]
        )
E       Failed: nomatch: 'test_helper_as_regular_function.py PASSED'
E           and: '============================= test session starts =============================='
E           and: 'platform linux -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1'
E           and: 'rootdir: /tmp/pytest-of-builduser/pytest-0/test_helper_as_regular_function0'
E           and: 'collected 0 items / 1 error'
E           and: ''
E           and: '==================================== ERRORS ===================================='
E           and: '_____________ ERROR collecting test_helper_as_regular_function.py ______________'
E           and: 'test_helper_as_regular_function.py:3: in <module>'
E           and: '    @pytest.helpers.register'
E           and: "E   AttributeError: module 'pytest' has no attribute 'helpers'"
E           and: '=========================== short test summary info ============================'
E           and: "ERROR test_helper_as_regular_function.py - AttributeError: module 'pytest' ha..."
E           and: '!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!'
E           and: '=============================== 1 error in 0.05s ==============================='
E       remains unmatched: 'test_helper_as_regular_function.py PASSED'

/build/python-pytest-helpers-namespace/src/python-pytest-helpers-namespace-2021.4.29/tests/test_helpers_namespace.py:237: Failed
----------------------------- Captured stdout call -----------------------------
running: /usr/bin/python -mpytest --basetemp=/tmp/pytest-of-builduser/pytest-0/test_helper_as_regular_function0/runpytest-0 -s
     in: /tmp/pytest-of-builduser/pytest-0/test_helper_as_regular_function0
============================= test session starts ==============================
platform linux -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/pytest-of-builduser/pytest-0/test_helper_as_regular_function0
collected 0 items / 1 error

==================================== ERRORS ====================================
_____________ ERROR collecting test_helper_as_regular_function.py ______________
test_helper_as_regular_function.py:3: in <module>
    @pytest.helpers.register
E   AttributeError: module 'pytest' has no attribute 'helpers'
=========================== short test summary info ============================
ERROR test_helper_as_regular_function.py - AttributeError: module 'pytest' ha...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.05s ===============================
_________________________ test_helper_with_custom_name _________________________

testdir = <Testdir local('/tmp/pytest-of-builduser/pytest-0/test_helper_with_custom_name0')>

    def test_helper_with_custom_name(testdir):
        testdir.makepyfile(
            """
            import pytest
    
            @pytest.helpers.register('jump')
            def foo():
                return 'bar'
    
            def test_helpers():
                assert pytest.helpers.jump() == 'bar'
                assert foo() == 'bar'
                print('PASSED')
        """
        )
    
        result = testdir.runpytest_subprocess("-s")
    
        # fnmatch_lines does an assertion internally
>       result.stdout.fnmatch_lines(
            [
                "test_helper_with_custom_name.py PASSED",
            ]
        )
E       Failed: nomatch: 'test_helper_with_custom_name.py PASSED'
E           and: '============================= test session starts =============================='
E           and: 'platform linux -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1'
E           and: 'rootdir: /tmp/pytest-of-builduser/pytest-0/test_helper_with_custom_name0'
E           and: 'collected 0 items / 1 error'
E           and: ''
E           and: '==================================== ERRORS ===================================='
E           and: '_______________ ERROR collecting test_helper_with_custom_name.py _______________'
E           and: 'test_helper_with_custom_name.py:3: in <module>'
E           and: "    @pytest.helpers.register('jump')"
E           and: "E   AttributeError: module 'pytest' has no attribute 'helpers'"
E           and: '=========================== short test summary info ============================'
E           and: "ERROR test_helper_with_custom_name.py - AttributeError: module 'pytest' has n..."
E           and: '!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!'
E           and: '=============================== 1 error in 0.05s ==============================='
E       remains unmatched: 'test_helper_with_custom_name.py PASSED'

/build/python-pytest-helpers-namespace/src/python-pytest-helpers-namespace-2021.4.29/tests/test_helpers_namespace.py:266: Failed
----------------------------- Captured stdout call -----------------------------
running: /usr/bin/python -mpytest --basetemp=/tmp/pytest-of-builduser/pytest-0/test_helper_with_custom_name0/runpytest-0 -s
     in: /tmp/pytest-of-builduser/pytest-0/test_helper_with_custom_name0
============================= test session starts ==============================
platform linux -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/pytest-of-builduser/pytest-0/test_helper_with_custom_name0
collected 0 items / 1 error

==================================== ERRORS ====================================
_______________ ERROR collecting test_helper_with_custom_name.py _______________
test_helper_with_custom_name.py:3: in <module>
    @pytest.helpers.register('jump')
E   AttributeError: module 'pytest' has no attribute 'helpers'
=========================== short test summary info ============================
ERROR test_helper_with_custom_name.py - AttributeError: module 'pytest' has n...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.05s ===============================
=========================== short test summary info ============================
FAILED tests/test_helpers_namespace.py::test_namespace - Failed: remains unma...
FAILED tests/test_helpers_namespace.py::test_nested_namespace - Failed: remai...
FAILED tests/test_helpers_namespace.py::test_unregistered_namespace - Failed:...
FAILED tests/test_helpers_namespace.py::test_namespace_override - Failed: nom...
FAILED tests/test_helpers_namespace.py::test_namespace_override_2 - Failed: n...
FAILED tests/test_helpers_namespace.py::test_helper_override - Failed: nomatc...
FAILED tests/test_helpers_namespace.py::test_helper_as_regular_function - Fai...
FAILED tests/test_helpers_namespace.py::test_helper_with_custom_name - Failed...
========================= 8 failed, 1 passed in 1.26s ==========================

Full build log:
python-pytest-helpers-namespace-2021.4.29-build.log

As I have a few other pytest plugins/extensions that I'm able to test this way, I'm currently unsure how to fix this. Maybe you have an idea?

archlinux-github pushed a commit to archlinux/svntogit-community that referenced this issue Jun 17, 2021
…4.29.

Disable most tests, as pytest is unable to pickup the plugin in check():
saltstack/pytest-helpers-namespace#10

git-svn-id: file:///srv/repos/svn-community/svn@964697 9fca08f4-af9d-4005-b8df-a31f2cc04f65
archlinux-github pushed a commit to archlinux/svntogit-community that referenced this issue Jun 17, 2021
…4.29.

Disable most tests, as pytest is unable to pickup the plugin in check():
saltstack/pytest-helpers-namespace#10

git-svn-id: file:///srv/repos/svn-community/svn@964697 9fca08f4-af9d-4005-b8df-a31f2cc04f65
@ssbarnea
Copy link

ssbarnea commented Jul 18, 2021

I got the same problem with mypy after upgrading mypy from 0.790 to 0.901 and I am not yet sure how to avoid it.

I would expect such an error if the python package would not be installed, but it is clearly installed.

ssbarnea added a commit to ansible/molecule that referenced this issue Jul 18, 2021
ssbarnea added a commit to ansible/molecule that referenced this issue Jul 18, 2021
ssbarnea added a commit to ansible/molecule that referenced this issue Jul 19, 2021
ssbarnea added a commit to ansible/molecule that referenced this issue Jul 19, 2021
@s0undt3ch
Copy link
Contributor

The way the plugin makes all of this magic work is by running some code early enough.

Don't know why that's happening, though I'm going to push some changes and let's see if it solves the issue.

@s0undt3ch
Copy link
Contributor

Could you please test the latest version and report back to see if it's still an issue?

@s0undt3ch
Copy link
Contributor

Also, are you setting pytest_plugins = ["helpers_namespace"] on your main conftest.py?

@dvzrv
Copy link
Author

dvzrv commented Dec 30, 2021

@s0undt3ch Thanks a lot! 2021.12.29 works as expected with all tests! :)

@dvzrv dvzrv closed this as completed Dec 30, 2021
@s0undt3ch
Copy link
Contributor

Awesome!

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

No branches or pull requests

3 participants