Skip to content

Tox/Poetry issue when running with pre-commit #2856

Description

@razy69

Issue

Hello everyone,

I encounter a strange issue while using pre-commit with tox/poetry.
I have to run pre-commit with PRE_COMMIT_COLOR=never to make it works.
The issue appears with tox 4.0.12 and still not resolved in 4.2.8.

Environment

Provide at least:

  • OS: darwin
  • pip list of the host Python where tox is installed:
$ pip list
Package              Version
-------------------- -----------
attrs                22.2.0
CacheControl         0.12.11
cachetools           5.2.1
certifi              2022.12.7
cffi                 1.15.1
cfgv                 3.3.1
chardet              5.1.0
charset-normalizer   2.1.1
cleo                 2.0.1
colorama             0.4.6
crashtest            0.4.1
distlib              0.3.6
dulwich              0.20.50
filelock             3.9.0
html5lib             1.1
identify             2.5.12
idna                 3.4
importlib-metadata   6.0.0
jaraco.classes       3.2.3
jsonschema           4.17.3
keyring              23.13.1
lockfile             0.12.2
more-itertools       9.0.0
msgpack              1.0.4
nodeenv              1.7.0
packaging            23.0
pexpect              4.8.0
pip                  22.3.1
pkginfo              1.9.6
platformdirs         2.6.2
pluggy               1.0.0
poetry               1.3.2
poetry-core          1.4.0
poetry-plugin-export 1.2.0
pre-commit           2.21.0
ptyprocess           0.7.0
pycparser            2.21
pyproject_api        1.4.0
pyrsistent           0.19.3
PyYAML               6.0
rapidfuzz            2.13.7
requests             2.28.1
requests-toolbelt    0.10.1
setuptools           58.1.0
shellingham          1.5.0.post1
six                  1.16.0
tomli                2.0.1
tomlkit              0.11.6
tox                  4.2.8
trove-classifiers    2022.12.22
urllib3              1.26.13
virtualenv           20.17.1
webencodings         0.5.1
xattr                0.10.1
zipp                 3.11.0

python >= 3.10
tox > 4.0.11
poetry > 1.3.0
pre-commit >= 2.20.0

tox.ini

[tox]
isolated_build = true
system_site_packages = false
no_package = true
env_list = {tests}

[testenv]
always_copy = true
download = true
base_python = python3.10
skip_install = true

[testenv:tests]
description = Run unit tests with pytest
allowlist_externals =
    poetry
commands_pre =
    poetry install -vvv --sync --with tests
commands =
    poetry run pytest -v {posargs}

.pre-commit-config.yaml

fail_fast: true
default_install_hook_types: [pre-commit]
repos:
- repo: local
  hooks:
  - id: tox-code-checks
    name: Run tox targets -- tests
    stages: [commit]
    language: system
    types: [python]
    pass_filenames: false
    verbose: true
    entry: tox -vvv -e tests

Minimal example

Running tox directly:

$ tox -e tests
tests: commands_pre[0]> poetry install -vvv --sync --with tests
Loading configuration file /Users/jdacunha/Library/Preferences/pypoetry/config.toml
Loading configuration file /Users/jdacunha/Library/Preferences/pypoetry/auth.toml
Adding repository XXX (https://XXX/simple)
Using virtualenv: /Users/jdacunha/Dev/project/.tox/tests
Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 0 installs, 0 updates, 0 removals, 71 skipped

  • Installing anyio (3.6.2): Pending...
  • Installing anyio (3.6.2): Skipped for the following reason: Already installed
  • Installing dogpile-cache (1.1.8): Pending...
  • Installing dogpile-cache (1.1.8): Skipped for the following reason: Already installed
  • Installing cffi (1.15.1): Pending...

  ...

tests: commands[0]> poetry run pytest -v
================================================= test session starts =================================================
platform darwin -- Python 3.10.5, pytest-7.2.0, pluggy-1.0.0 -- /Users/jdacunha/Dev/project/.tox/tests/bin/python
cachedir: .tox/tests/.pytest_cache
rootdir: /Users/jdacunha/Dev/project, configfile: pyproject.toml
plugins: recording-0.12.1, cov-4.0.0, anyio-3.6.2
collected 381 items
  ...

================================================= slowest 5 durations =================================================
1.01s call     tests/unit/common/a.py::TestA::a
1.01s call     tests/unit/common/b.py::TestB::b
0.13s call     tests/unit/common/c.py::TestC::c
0.11s call     tests/unit/common/d.py::TestD::d
0.11s call     tests/unit/common/e.py::TestE::e
========================================== 381 passed, 19 warnings in 10.19s ==========================================
  tests: OK (13.13=setup[0.06]+cmd[1.41,11.65] seconds)
  congratulations :) (13.21 seconds)

Running pre-commit:

$ pre-commit run tox-code-checks
Run tox targets -- tests.......................Failed
- hook id: tox-code-checks
- duration: 1.71s
- exit code: 1

ROOT: 193 D setup logging to NOTSET on pid 96007 [tox/report.py:221]
tests: 258 I find interpreter for spec PythonSpec(major=3, minor=10) [virtualenv/discovery/builtin.py:56]
tests: 258 D discover exe for PythonInfo(spec=CPython3.10.5.final.0-64, exe=/Users/jdacunha/Dev/project/.venv/bin/python3, platform=darwin, version='3.10.5 (main, Jan 10 2023, 15:36:10) [Clang 14.0.0 (clang-1400.0.29.102)]', encoding_fs_io=utf-8-utf-8) in /Users/jdacunha/.pyenv/versions/3.10.5 [virtualenv/discovery/py_info.py:437]
tests: 259 D filesystem is not case-sensitive [virtualenv/info.py:24]
tests: 260 D got python info of /Users/jdacunha/.pyenv/versions/3.10.5/bin/python3.10 from /Users/jdacunha/Library/Application Support/virtualenv/py_info/1/ec7cb05918b9d40294b520615642683600e9927f06d12b706d7bab5356c36c9c.json [virtualenv/app_data/via_disk_folder.py:129]
tests: 260 I proposed PythonInfo(spec=CPython3.10.5.final.0-64, system=/Users/jdacunha/.pyenv/versions/3.10.5/bin/python3.10, exe=/Users/jdacunha/Dev/project/.venv/bin/python3, platform=darwin, version='3.10.5 (main, Jan 10 2023, 15:36:10) [Clang 14.0.0 (clang-1400.0.29.102)]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:63]
tests: 260 D accepted PythonInfo(spec=CPython3.10.5.final.0-64, system=/Users/jdacunha/.pyenv/versions/3.10.5/bin/python3.10, exe=/Users/jdacunha/Dev/project/.venv/bin/python3, platform=darwin, version='3.10.5 (main, Jan 10 2023, 15:36:10) [Clang 14.0.0 (clang-1400.0.29.102)]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:65]
tests: 286 W commands_pre[0]> poetry install -vvv --sync --with tests [tox/tox_env/api.py:427]
Loading configuration file /Users/jdacunha/Library/Preferences/pypoetry/config.toml
Loading configuration file /Users/jdacunha/Library/Preferences/pypoetry/auth.toml
Adding repository XXX (https://XXX/simple)
Using virtualenv: /Users/jdacunha/Dev/project/.tox/tests
Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 0 installs, 0 updates, 0 removals, 71 skipped

tests: 1669 C exit 1 (1.38 seconds) /Users/jdacunha/Dev/project> poetry install -vvv --sync --with tests pid=96008 [tox/execute/api.py:275]
  tests: FAIL code 1 (1.42=setup[0.04]+cmd[1.38] seconds)
  evaluation failed :( (1.48 seconds)

Running pre-commit with PRE_COMMIT_COLOR=never

$ PRE_COMMIT_COLOR=never pre-commit run tox-code-checks
Run tox targets -- tests.......................Passed
- hook id: tox-code-checks
- duration: 13.32s

ROOT: 192 D setup logging to NOTSET on pid 97155 [tox/report.py:221]
tests: 257 I find interpreter for spec PythonSpec(major=3, minor=10) [virtualenv/discovery/builtin.py:56]
tests: 257 D discover exe for PythonInfo(spec=CPython3.10.5.final.0-64, exe=/Users/jdacunha/Dev/project/.venv/bin/python3, platform=darwin, version='3.10.5 (main, Jan 10 2023, 15:36:10) [Clang 14.0.0 (clang-1400.0.29.102)]', encoding
_fs_io=utf-8-utf-8) in /Users/jdacunha/.pyenv/versions/3.10.5 [virtualenv/discovery/py_info.py:437]
tests: 258 D filesystem is not case-sensitive [virtualenv/info.py:24]
tests: 259 D got python info of /Users/jdacunha/.pyenv/versions/3.10.5/bin/python3.10 from /Users/jdacunha/Library/Application Support/virtualenv/py_info/1/ec7cb05918b9d40294b520615642683600e9927f06d12b706d7bab5356c36c9c.json [virtualen
v/app_data/via_disk_folder.py:129]
tests: 259 I proposed PythonInfo(spec=CPython3.10.5.final.0-64, system=/Users/jdacunha/.pyenv/versions/3.10.5/bin/python3.10, exe=/Users/jdacunha/Dev/project/.venv/bin/python3, platform=darwin, version='3.10.5 (main, Jan 10 2023, 15:
36:10) [Clang 14.0.0 (clang-1400.0.29.102)]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:63]
tests: 260 D accepted PythonInfo(spec=CPython3.10.5.final.0-64, system=/Users/jdacunha/.pyenv/versions/3.10.5/bin/python3.10, exe=/Users/jdacunha/Dev/project/.venv/bin/python3, platform=darwin, version='3.10.5 (main, Jan 10 2023, 15:
36:10) [Clang 14.0.0 (clang-1400.0.29.102)]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:65]
tests: 285 W commands_pre[0]> poetry install -vvv --sync --with tests [tox/tox_env/api.py:427]
Loading configuration file /Users/jdacunha/Library/Preferences/pypoetry/config.toml
Loading configuration file /Users/jdacunha/Library/Preferences/pypoetry/auth.toml
Adding repository XXX (https://XXX/simple)
Using virtualenv: /Users/jdacunha/Dev/project/.tox/tests
Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 0 installs, 0 updates, 0 removals, 71 skipped

  • Installing anyio (3.6.2): Skipped for the following reason: Already installed
  • Installing appdirs (1.4.4): Skipped for the following reason: Already installed
  ...

tests: 13277 I exit 0 (11.62 seconds) /Users/jdacunha/Dev/project> poetry run pytest -v pid=97161 [tox/execute/api.py:275]
  tests: OK (13.03=setup[0.05]+cmd[1.35,11.62] seconds)
  congratulations :) (13.09 seconds)

Does anyone succeed to make them work together ?
Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions