https://pantsbuild.org/ logo
#general
Title
# general
f

future-oxygen-10553

04/20/2023, 12:29 PM
Hi, I’m trying to use a custom version of pytest for my repo using 2.16.0rc0. I have a `dev-requirements.txt`:
Copy code
pytest==7.2.2
pytest-cov==4.0.0
pytest-xdist==3.2.1
and my
pants.toml
Copy code
...
[python.resolves]
python-default = "3rdparty/python-lock.txt"
dev = "utils/lock.txt"
...
[pytest]
args = ["--no-header", "-vv"]
install_from_resolve = "dev"
However, running
pants test ::
gives me
Copy code
1. /opt/homebrew/Cellar/python@3.10/3.10.11/Frameworks/Python.framework/Versions/3.10/bin/python3.10:
    Failed to resolve all requirements for cp310-cp310-macosx_13_0_arm64 interpreter at /opt/homebrew/Cellar/python@3.10/3.10.11/Frameworks/Python.framework/Versions/3.10/bin/python3.10 from utils/lock.txt:

Configured with:
    build: True
    use_wheel: True

Dependency on pytest-cov not satisfied, 1 incompatible candidate found:
1.) pytest-cov 4 does not satisfy the following requirements:
    !=2.12.1,<3.1,>=2.12 (via: pytest-cov!=2.12.1,<3.1,>=2.12)

Dependency on pytest-xdist not satisfied, 1 incompatible candidate found:
1.) pytest-xdist 3.2.1 does not satisfy the following requirements:
    <3,>=2.5 (via: pytest-xdist<3,>=2.5)

Dependency on pytest not satisfied, 1 incompatible candidate found:
1.) pytest 7.2.2 does not satisfy the following requirements:
    ==7.0.1 (via: pytest==7.0.1)
Those versions are indeed hard-coded in the pytest subsystem, but the docs say that the method I’m trying is the right way to override things
s

sparse-lifeguard-95737

04/20/2023, 12:50 PM
you also need to override
[pytest].requirements
(there are some hard-coded default requirements as a sanity-check). in my repo I have:
Copy code
[pytest]
requirements = [
  "pytest",
  "pytest-cov",
  "pytest-xdist",
]
which effectively disables any additional version-checking, so whatever’s in the lockfile is always valid
f

future-oxygen-10553

04/20/2023, 12:57 PM
Ah, thank you! I’ll try that
Thanks, that worked perfectly! I’ll submit a PR to update the docs
h

happy-kitchen-89482

04/20/2023, 1:26 PM
Thanks!! I thought this was in the docs, but obviously it's not clear enough
f

future-oxygen-10553

04/20/2023, 3:04 PM
@happy-kitchen-89482 I’m wondering how best to clarify this section. I see the note in the
pants.toml
example that you can replace
requirements
instead of `.add`ing to it. However, the
pytest-requirements.txt
example just below that includes
pytest
,
pytest-cov
, and
pytest-xdist
. Based on my experience in this thread, I’m pretty sure that example would fail with the message in the OP. Should I remove the default requirements from that example requirements.txt and add another one to show how to replace pytest itself?
h

happy-kitchen-89482

04/20/2023, 3:05 PM
Link?
Also, the “Linters and Formatters” docs don’t mention the new way of doing things: https://www.pantsbuild.org/v2.16/docs/python-linters-and-formatters#configuring-the-tools-eg-adding-plugins Should I look at updating that as well?
h

happy-kitchen-89482

04/20/2023, 3:11 PM
Oh oops, thanks! That would be excellent.
And re the existing text - yeah, not terribly clear. An example would be good.
Although, another possibility is - since this is tripping people up over and over again, to get rid of the problem entirely, by using the unversioned project names when we resolve the tool from the lockfile, under the assumption that we don't need to babysit the user - if they want to YOLO it with some version Pants hasn't been tested against, that's on them
Right now this
requirements
thing functions as a warning, to say "Pants doesn't know if it can work with this version". But maybe this is over-nannying
f

future-oxygen-10553

04/21/2023, 2:51 PM
@happy-kitchen-89482 So for that second option, where should I look in pants to change that behavior?
h

happy-kitchen-89482

04/21/2023, 3:21 PM
I'll tackle it, since I'm already futzing in that code, and have a good idea of how to do it
f

future-oxygen-10553

04/21/2023, 3:42 PM
Thanks! I’ll send a pr to update the linters docs page then