I want to pytest my pants tests from vscode. is th...
# general
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
as well as a
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
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.
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?
Well, 1st off, reporting back if my suggestion just above worked.
doesn’t recognize the flag
. the flag doesn’t seem to be documented: https://www.pantsbuild.org/docs/reference-export
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 ?
I can give it a shot
Great. Rememer,
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!
we don’t have
in any pants configuration
Even in 2.14.0 if you have enabled resolves, export will export venvs for all tools plus your resolve - the 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.
ah, why is it not true by default then 😆 i’ll try
@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.
i’ve set
enable_resolves = true
rm -rf ~/.cache/pants ~/.pex dist .pids .pants.d
, then
./pants generate-lockfiles --resolve=pytest
./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
field: “3rdparty/python/default.lock”`
So, a 1 time step after enabling resolves is generating the lock file.
./pants generate-lockfiles
I was doing
./pants generate-lockfiles --lockfile=pytest
already. i need to remove the flag
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
ok i have the env, but I see it’s missing
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
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.
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