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

Unable to run tox tests #1837

Closed
evoludigit opened this issue Apr 1, 2023 · 6 comments
Closed

Unable to run tox tests #1837

evoludigit opened this issue Apr 1, 2023 · 6 comments

Comments

@evoludigit
Copy link
Contributor

evoludigit commented Apr 1, 2023

  • Faker version: v18.3.1
  • OS: Arch Linux x86_64

It is my first time running tox tests from a packaged module, so it might be an error from me.

If not, it seems like an upstream error.

Steps to reproduce

  1. git clone https://github.com/joke2k/faker.git
  2. cd faker
  3. python -m venv faker_venv
  4. source faker_venv/bin/activate
  5. pip install -e .
  6. tox

Expected behavior

run tests correctly

Actual behavior

Traceback (most recent call last):
  File "/usr/bin/tox", line 33, in <module>
    sys.exit(load_entry_point('tox==3.26.0', 'console_scripts', 'tox')())
  File "/usr/bin/tox", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.10/site-packages/tox/__init__.py", line 32, in <module>
    from .session import cmdline  # isort:skip
  File "/usr/lib/python3.10/site-packages/tox/session/__init__.py", line 20, in <module>
    from tox import reporter
  File "/usr/lib/python3.10/site-packages/tox/reporter.py", line 127, in <module>
    _INSTANCE = Reporter()
  File "/usr/lib/python3.10/site-packages/tox/reporter.py", line 32, in __init__
    self._reset(**kwargs)
  File "/usr/lib/python3.10/site-packages/tox/reporter.py", line 38, in _reset
    self.tw = py.io.TerminalWriter()
AttributeError: module 'py' has no attribute 'io'
@stefan6419846
Copy link
Contributor

Which version of pytest are you using (pip show pytest)? pytest-dev/pytest#10396, which is included since pytest 7.2.0, dropped the vendored py package.

It seems like recent tox versions refactored this code, so we might need a tox upgrade here.

@evoludigit
Copy link
Contributor Author

evoludigit commented Apr 1, 2023

I had not install pytest in the faker_venv, after pip install pytest, I get the sameAttributeError: module 'py' has no attribute 'io' on pytest 7.2.2.

@stefan6419846
Copy link
Contributor

pytest should have been installed automatically by tox, at least in the corresponding test environments (which might not correspond to your virtual environment):

pytest>=6.0.1
You might try to replace the offending line with pytest>=6.0.1,<7.2.0, although I have not tested it. Nevertheless, I am not completely sure here as my knowledge of tox is rather limited.

@evoludigit
Copy link
Contributor Author

evoludigit commented Apr 1, 2023

I did this, but without success:

modify tox.ini

line 9: pytest>=6.0.1,<7.2.0

uninstall pytest

(faker_venv) [evoludigit@linuxbox ~/code/faker]$ pip uninstall pytest
Found existing installation: pytest 7.2.2
Uninstalling pytest-7.2.2:
  Would remove:
    /home/evoludigit/code/faker/faker_venv/bin/py.test
    /home/evoludigit/code/faker/faker_venv/bin/pytest
    /home/evoludigit/code/faker/faker_venv/lib/python3.10/site-packages/_pytest/*
    /home/evoludigit/code/faker/faker_venv/lib/python3.10/site-packages/py.py
    /home/evoludigit/code/faker/faker_venv/lib/python3.10/site-packages/pytest-7.2.2.dist-info/*
    /home/evoludigit/code/faker/faker_venv/lib/python3.10/site-packages/pytest/*
Proceed (Y/n)? Y
  Successfully uninstalled pytest-7.2.2

launch tox without pytest installed

(faker_venv) [evoludigit@linuxbox ~/code/faker]$ tox
Traceback (most recent call last):
  File "/usr/bin/tox", line 33, in <module>
    sys.exit(load_entry_point('tox==3.26.0', 'console_scripts', 'tox')())
  File "/usr/bin/tox", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.10/site-packages/tox/__init__.py", line 32, in <module>
    from .session import cmdline  # isort:skip
  File "/usr/lib/python3.10/site-packages/tox/session/__init__.py", line 20, in <module>
    from tox import reporter
  File "/usr/lib/python3.10/site-packages/tox/reporter.py", line 127, in <module>
    _INSTANCE = Reporter()
  File "/usr/lib/python3.10/site-packages/tox/reporter.py", line 32, in __init__
    self._reset(**kwargs)
  File "/usr/lib/python3.10/site-packages/tox/reporter.py", line 38, in _reset
    self.tw = py.io.TerminalWriter()
AttributeError: module 'py' has no attribute 'io'

tox does not install pytest:

(faker_venv) [evoludigit@linuxbox ~/code/faker]$ pip show pytest
WARNING: Package(s) not found: pytest

Force reinstallation of pytest 6.2.5: same error when launching tox

(faker_venv) [evoludigit@linuxbox~/code/faker]$ pip install --force-reinstall -v "pytest==6.2.5"
Using pip 22.3.1 from /home/evoludigit/code/faker/faker_venv/lib/python3.10/site-packages/pip (python 3.10)
Collecting pytest==6.2.5

(faker_venv) [evoludigit@linuxbox ~/code/faker]$ tox
Traceback (most recent call last):
 File "/usr/bin/tox", line 33, in <module>
   sys.exit(load_entry_point('tox==3.26.0', 'console_scripts', 'tox')())
 File "/usr/bin/tox", line 25, in importlib_load_entry_point
   return next(matches).load()
 File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
   module = import_module(match.group('module'))
 File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
   return _bootstrap._gcd_import(name[level:], package, level)
 File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
 File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
 File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
 File "<frozen importlib._bootstrap_external>", line 883, in exec_module
 File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
 File "/usr/lib/python3.10/site-packages/tox/__init__.py", line 32, in <module>
   from .session import cmdline  # isort:skip
 File "/usr/lib/python3.10/site-packages/tox/session/__init__.py", line 20, in <module>
   from tox import reporter
 File "/usr/lib/python3.10/site-packages/tox/reporter.py", line 127, in <module>
   _INSTANCE = Reporter()
 File "/usr/lib/python3.10/site-packages/tox/reporter.py", line 32, in __init__
   self._reset(**kwargs)
 File "/usr/lib/python3.10/site-packages/tox/reporter.py", line 38, in _reset
   self.tw = py.io.TerminalWriter()
AttributeError: module 'py' has no attribute 'io'

@stefan6419846
Copy link
Contributor

You are using tox==3.26.0 from the system installation (/usr/bin/tox), while CI uses the latest 4.4.8 release. https://archlinux.org/packages/community/any/python-tox/ is flagged out-of-date as of today.

Please try to install tox within the virtual environment and run tox again, which works for me. You might want to verify the location of the tox binary with which tox.

@evoludigit
Copy link
Contributor Author

thanks, that was it indeed ! :-)

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

2 participants