I finally figured it out working on another problem. The problem was that my test couldn't find an import.

It looks like you get the above error if your test fails to import. This makes sense because the test suite can't import a broken test. At least I think this is what is going on because I fixed the import within my test file and sure enough it started working.

To validate your test case just try import the test case file in python console.

Example:

from project.apps.app1.tests import *
Answer from Chris on Stack Overflow
🌐
GitHub
github.com › pytest-dev › pytest › issues › 10420
`pytest-benchmark`: AttributeError: module 'py' has no attribute 'io' · Issue #10420 · pytest-dev/pytest
October 25, 2022 - Closed as not planned · pytest-benchmark: AttributeError: module 'py' has no attribute 'io'#10420 · Copy link · ocelotl · opened · on Oct 25, 2022 · Issue body actions ·
Author   ocelotl
Discussions

Getting AttributeError: module 'pytest' has no attribute 'main' error while executing the script | Selenium Python Forum
Getting AttributeError: module 'pytest' has no attribute 'main' error while executing the script .Showing uo below error message after running the pytest code. More on seleniumtraining.com
🌐 seleniumtraining.com
March 29, 2020
Pytest - "module 'pytest' has no attribute 'fixture' "
Probably your import statement is wrong, but no way to tell as you didnt include any of your code. More on reddit.com
🌐 r/AskProgramming
3
1
February 25, 2023
Python Testing with pytest - Chapter 5 example c AttributeError: 'module' object has no attribute 'config'
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particular the code: ​$ ​​cd​​ ​​/path/to/code/ch5/c/tasks_proj/tests/func​ ​ $ ​​pytest​​ ​​--tb=no​​ ​​test_api_exc... More on forum.devtalk.com
🌐 forum.devtalk.com
0
3
July 14, 2020
azure - AttributeError: module 'pytest' has no attribute 'config' - Stack Overflow
I followed this tutorial (Build DevOps CI/CD pipeline for Python Flask with Azure DevOps). There is a command line task to execute a functional test which I get an error while running it. The command More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › pytest-dev › pytest › discussions › 7998
AttributeError: ‘module’ object has no attribute ‘PLUGIN_MANAGER_ADDHOOKS’ · pytest-dev/pytest · Discussion #7998
AttributeError: 'module' object has no attribute 'PLUGIN_MANAGER_ADDHOOKS' <auto> node--202 ubuntu@1xxxx~$ /usr/local/bin/py.test --version Traceback (most recent call last): File "/usr/local/bin/py.test", line 8, in <module> sys.exit(main()) File "/home/ubuntu/.local/lib/python2.7/site-packages/_pytest/config/__init__.py", line 65, in main config = _prepareconfig(args, plugins) File "/home/ubuntu/.local/lib/python2.7/site-packages/_pytest/config/__init__.py", line 214, in _prepareconfig pluginmanager=pluginmanager, args=args File "/home/ubuntu/.local/lib/python2.7/site-packages/pluggy/hooks.p
Author   pytest-dev
🌐
Reddit
reddit.com › r/askprogramming › pytest - "module 'pytest' has no attribute 'fixture' "
r/AskProgramming on Reddit: Pytest - "module 'pytest' has no attribute 'fixture' "
February 25, 2023 -

I'm trying to use "@pytest.fixture(scope="class")" But am getting this error:

AttributeError: module 'pytest' has no attribute 'fixture'

Am i using the wrong Pytest version? My version is 7.2.1

import pytest
from selenium import webdriver
import os

@pytest.fixture(scope="class")
def init_driver(request):
supported_browsers= ['chrome' , 'firefox']

browser = os.environ.get('BROWSER')

driver = webdriver.Chrome()
if not browser:
raise Exception("The environment variable 'BROWSER' must be set")
browser = browser.lower()
if browser not in supported_browsers:
raise Exception(f"Provided browser '{browser}' is not supported"
f"Supported browsers are: {supported_browsers}")
if browser in ('chrome'):
driver = webdriver
elif browser in ('firefox'):
driver = webdriver.Firefox()

request.cls.driver = driver
yield
driver.quit()

🌐
JetBrains
youtrack.jetbrains.com › issue › PY-43759
module 'pytest' has no attribute 'hookimpl'" running tests in ...
August 10, 2020 - {{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Devtalk
forum.devtalk.com › pragmatic bookshelf › pragprog customers
Python Testing with pytest - Chapter 5 example c AttributeError: 'module' object has no attribute 'config' - PragProg Customers - Devtalk
July 14, 2020 - Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particular the code: ​$ ​​cd​​ ​​/path/to/code/ch5/c/tasks_proj/tests/func​ ​ $ ​​pytest​​ ​​--tb=no​​ ​​test_api_exc...
🌐
Edureka Community
edureka.co › home › community › categories › python › error attributeerror module object has no...
Error AttributeError module object has no attribute tests | Edureka Community
August 7, 2020 - I'm running this command: python manage.py test project.apps.app1.tests and it causes this error: ... ' object has no attribute 'tests' Any help?
Find elsewhere
🌐
GitHub
github.com › pytest-dev › pytest › issues › 10422
Version `7.2.0` AttributeError: module 'py' has no attribute 'io' · Issue #10422 · pytest-dev/pytest
October 25, 2022 - Hey there! Since upgrading to the latest release 7.2.0, I've been seeing the following stack trace when running pytest in Azure CI: INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/usr/local/lib/python3.7/site-pack...
Author   cdkini
🌐
GitHub
github.com › pytest-dev › pytest › issues › 3618
AttributeError: module 'py' has no attribute 'builtin' · Issue #3618 · pytest-dev/pytest
June 25, 2018 - Traceback (most recent call last): File "/home/bfortuner/.pyenv/versions/3.6.2/bin/pytest", line 7, in <module> from pytest import main File "/home/bfortuner/.pyenv/versions/3.6.2/lib/python3.6/site-packages/pytest.py", line 10, in <module> from _pytest.fixtures import fixture, yield_fixture File "/home/bfortuner/.pyenv/versions/3.6.2/lib/python3.6/site-packages/_pytest/fixtures.py", line 12, in <module> from py._code.code import FormattedExcinfo File "/home/bfortuner/.pyenv/versions/3.6.2/lib/python3.6/site-packages/py/_code/code.py", line 7, in <module> reprlib = py.builtin._tryimport('repr', 'reprlib') AttributeError: module 'py' has no attribute 'builtin' Output of pip freeze: atomicwrites==1.1.5 attrs==18.1.0 certifi==2018.4.16 more-itertools==4.2.0 pipenv==2018.6.25 pluggy==0.6.0 py==1.5.3 pytest==3.6.2 six==1.11.0 virtualenv==16.0.0 virtualenv-clone==0.3.0 ·
Author   bfortuner
🌐
GitHub
github.com › pytest-dev › pytest-forked › issues › 88
AttributeError: module 'py' has no attribute 'process' · Issue #88 · pytest-dev/pytest-forked
February 11, 2024 - Hello! I'm getting the following traceback when trying to use pytest-forked, but when looking through the output of dir(py) right before ff = py.process.ForkedFunc(runforked), py does indeed seem to have process, so I'm not sure what the...
Author   sylvorg
🌐
GitHub
github.com › pytest-dev › pytest › issues › 1944
AttributeError: 'Module' object has no attribute '_obj' · Issue #1944 · pytest-dev/pytest
September 18, 2016 - % uname -a Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt4-3 (2015-02-03) x86_64 GNU/Linux % cat test.py def f(): return assert f() == 10 % pytest test.py platform linux -- Python 3.4.2, pytest-3.0.2, py-1.4.31, pluggy-0.3.1 ___________________________ ERROR collecting test.py _____________________________ env/lib/python3.4/site-packages/_pytest/python.py:209: in fget return self._obj E AttributeError: 'Module' object has no attribute '_obj'
Published   Sep 18, 2016
🌐
GitHub
github.com › pytest-dev › pytest › issues › 1688
module has no attribute `config` when accessing `pytest.config` in conftest · Issue #1688 · pytest-dev/pytest
June 29, 2016 - $ py.test xxx/tests/resource/test_tasks.py Traceback (most recent call last): File "/Users/bwm/findable/virtualenvs/xxx/lib/python2.7/site-packages/_pytest/config.py", line 320, in _importconftest mod = conftestpath.pyimport() File "/Users/bwm/findable/virtualenvs/xxx/lib/python2.7/site-packages/py/_path/local.py", line 650, in pyimport __import__(modname) File "/Users/bwm/projects/Xxx/xxx/tests/conftest.py", line 13, in <module> datadir = pytest.config.rootdir.join('xxx/tests/data') AttributeError: 'module' object has no attribute 'config' ERROR: could not load /Users/bwm/projects/Xxx/xxx/tests/conftest.py
Author   quodlibetor
🌐
GitHub
github.com › pytest-dev › pytest › issues › 281
pytest object has no attribute 'main' · Issue #281 · pytest-dev/pytest
March 21, 2013 - **Traceback (most recent call last): File "mytest_1.py", line 7, in <module> pytest.main("-qq", plugins=[MyPlugin()]) AttributeError: 'module' object has no attribute 'main'** and the expected is: *** test run reporting finishing ·
Author   pytestbot
Top answer
1 of 2
1

Maybe your interpreter configured in PyDev is not the same one you're using in the command line?

-- pytest should definitely have pytest.main.

Please run the code below (as a regular launch without unit-testing both from the command line as well as from within Eclipse) and provide the output you have in those cases (it should make clear what's the executable and where pytest is being gotten from).

import sys

def inc(x):
    return x + 1

def test_inc_pass():
    assert inc(5) == 6

def test_inc_fail():
    assert inc(5) == 5

if __name__ == '__main__':
    import pytest
    print('Running in: %s' % (sys.executable,))
    print('PyTest found in: %s' % (pytest.__file__,))
    pytest.main(sys.argv)

2 of 2
0

Strange thing. For the first time, when i run your code from eclipse i got the same error as previously, but after restarting eclipse, i run it one more time and Your code works fine:

Running in: C:\MojeApps\Python365\python.exe
PyTest found in: C:\MojeApps\Python365\lib\site-packages\pytest\__init__.py
============================= test session starts =============================
platform win32 -- Python 3.6.5, pytest-6.0.0, py-1.9.0, pluggy-0.13.1
rootdir: C:\Development\eclipse_workspace\PySandbox\pytest_so_help
collected 2 items

main.py .F                                                               [100%]

================================== FAILURES ===================================
________________________________ test_inc_fail ________________________________

    def test_inc_fail():
>       assert inc(5) == 5
E       assert 6 == 5
E        +  where 6 = inc(5)

main.py:10: AssertionError
=========================== short test summary info ===========================
FAILED main.py::test_inc_fail - assert 6 == 5
========================= 1 failed, 1 passed in 0.03s =========================

and running "my tests" via eclipse gives me new error :)

============================= test session starts =============================
platform win32 -- Python 3.6.5, pytest-6.0.0, py-1.9.0, pluggy-0.13.1
rootdir: C:\Development\eclipse_workspace\MyPyTests\src
collected 2 items

tests\test_sample.py .F
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\_pytest\main.py", line 240, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\_pytest\main.py", line 296, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\_pytest\main.py", line 321, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\_pytest\runner.py", line 100, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\_pytest\runner.py", line 117, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\_pytest\runner.py", line 211, in call_and_report
INTERNALERROR>     hook.pytest_runtest_logreport(report=report)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\MojeApps\Python365\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\MojeApps\eclipse\plugins\org.python.pydev.core_7.6.0.202006041357\pysrc\_pydev_runfiles\pydev_runfiles_pytest2.py", line 265, in pytest_runtest_logreport
INTERNALERROR>     exc = _get_error_contents_from_report(report)
INTERNALERROR>   File "C:\MojeApps\eclipse\plugins\org.python.pydev.core_7.6.0.202006041357\pysrc\_pydev_runfiles\pydev_runfiles_pytest2.py", line 167, in _get_error_contents_from_report
INTERNALERROR>     tw = TerminalWriter(stringio=True)
INTERNALERROR> TypeError: __init__() got an unexpected keyword argument 'stringio'

========================= 1 failed, 1 passed in 0.05s =========================

I'm starting to think that pydev plugin is broken...

EDIT: Weird thing. After the night when I booted OS, and check if it still appears - it suddenly started to work without a problem - I have no idea...

🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-module-has-no-attribute
AttributeError: module 'X' has no attribute 'Y' in Python | bobbyhadz
April 8, 2024 - To solve the error, we first created ... the Python "AttributeError: module has no attribute", make sure you haven't named your local modules with names of remote modules, e.g....