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

glamorous-accountant-97217

12/07/2022, 11:11 PM
I want to pytest my pants tests from vscode. is this possible to do in a good way? (I see here I can’t exactly run pants from vscode) when I saw this documentation I tried
./pants export ::
and got some interpreters for tools under
virtualenvs
as well as a
virtualenv
that comes with message
Wrote virtualenv (using Python 3.10.8) to dist/export/python/virtualenv
. the pytest env had pytest and some dependencies on my project’s sources, but it was missing numpy, which is a transitively required third party dependency. am I doing something wrong?
bumping this post because I would love to be able to use vscode to debug and run tests for my pants project. i’d really appreciate help
e

enough-analyst-54434

12/12/2022, 7:25 PM
There's not much to go on there! I think that explains the lack of response. So, you'd want to point the IDE at your project's venv and not the tool pytest venv . By default that resolve name is `python-default`; so `./pants export --resolve=python-default`which will get you a venv for your project at `dist/export/python/virtualenvs/python-default/`to use. If that venv does not include pytest itself you'll need to add deps for it as a hack.
g

glamorous-accountant-97217

12/13/2022, 4:52 PM
ok, i appreciate the help. i thought i had given enough details in my post for someone more familiar with this problem to help. what other details would you like?
e

enough-analyst-54434

12/13/2022, 4:53 PM
Well, 1st off, reporting back if my suggestion just above worked.
g

glamorous-accountant-97217

12/13/2022, 4:53 PM
export
doesn’t recognize the flag
--resolve
. the flag doesn’t seem to be documented: https://www.pantsbuild.org/docs/reference-export
e

enough-analyst-54434

12/13/2022, 4:56 PM
Ah, sorry. I had tested in a repo I'm developing in and forgot I was on 2.15.0rc0: https://www.pantsbuild.org/v2.15/docs/reference-export#resolve
Are you in a position to try 2.15.0rc0 ?
g

glamorous-accountant-97217

12/13/2022, 4:57 PM
I can give it a shot
e

enough-analyst-54434

12/13/2022, 4:58 PM
Great. Rememer,
python-default
is just the default resolve name with you enable_resolves (https://www.pantsbuild.org/docs/reference-python#enable_resolves), if you've set up a custom resolve name, use that.
Or, just realizing now, perhaps the issue is you never enaled resolves at all!
g

glamorous-accountant-97217

12/13/2022, 4:59 PM
we don’t have
enable_resolves
in any pants configuration
e

enough-analyst-54434

12/13/2022, 4:59 PM
Even in 2.14.0 if you have enabled resolves, export will export venvs for all tools plus your resolve - the default
python-default
. The 2.15 improvement is to be able to export just 1 venv instead of all tools venvs + all your own.
Aha - that is the problem.
You really want that.
Makes Pants faster, and a host of other things. Gives you a real lock file, etc.
g

glamorous-accountant-97217

12/13/2022, 5:01 PM
ah, why is it not true by default then 😆 i’ll try
e

enough-analyst-54434

12/13/2022, 5:05 PM
@glamorous-accountant-97217 it was experimental for a while then graduated. If you flip a default you break people. We don't take that lightly. There is a balance between having good defaults and breaking people / trying to correct past mistakes.
g

glamorous-accountant-97217

12/13/2022, 5:06 PM
i’ve set
enable_resolves = true
,
rm -rf ~/.cache/pants ~/.pex dist .pids .pants.d
, then
./pants generate-lockfiles --resolve=pytest
and
./pants export
. The only outputs I get are my test tools in dist/export/python/virtualenvs/tools/
i’m on pants “2.13.0”
on pants 2.15.0rc0 with the same steps I have among other warnings `111201.18 [WARN] Unmatched glob from 3rdparty/python:python-default’s
sources
field: “3rdparty/python/default.lock”`
e

enough-analyst-54434

12/13/2022, 5:12 PM
So, a 1 time step after enabling resolves is generating the lock file.
./pants generate-lockfiles
g

glamorous-accountant-97217

12/13/2022, 5:13 PM
I was doing
./pants generate-lockfiles --lockfile=pytest
already. i need to remove the flag
e

enough-analyst-54434

12/13/2022, 5:13 PM
So, sorry - to be clear you absolutely do not want pytest
Stay away from that.
That will only get you pytest itself.
You want the resolve for your project.
So: 1. enable resolves 2. generate lockfiles (1x after any update to requirements and 1x the 1st time (now)) 3. export (or in 2.15.x export --resolve=python-default)
The the venv you want to set up in the IDE is not the pytest venv, its the
python-default
venv.
g

glamorous-accountant-97217

12/13/2022, 5:21 PM
ok i have the env, but I see it’s missing
pytest
as you said it might. isn’t that the correct behavior since my project itself shouldn’t depend on pytest?
by the way, i have been doing
./pants generate-lockfiles --lockfile=pytest
since the very beginning (even before solving this IDE problem) just to run my
./pants test
commands
e

enough-analyst-54434

12/13/2022, 5:33 PM
isn’t that the correct behavior since my project itself shouldn’t depend on pytest?
Yes, it's the correct behavior. Just not useful for you. So this is where I led with "If that venv does not include pytest itself you'll need to add deps for it as a hack."
There is probably a way to set up multiple resolves (Pants supports that) where the one resolve is the default + pytest and you only use that for IDE venvs. At that point I leave you to exploring the pantsbuild.org docs about multiple resolves.
g

glamorous-accountant-97217

12/13/2022, 5:35 PM
i was trying to ask whether i had the right behavior 😛 I forgot you called this a hack. i’ll try it
thank you so much for your help so far. I don’t have time to look more right now
7 Views