fast-photographer-12719
11/13/2023, 2:08 PMbetter-van-82973
11/13/2023, 2:11 PMfast-photographer-12719
11/13/2023, 2:13 PMfast-photographer-12719
11/13/2023, 2:14 PMbetter-van-82973
11/13/2023, 2:15 PMtests
underneath the package dir. We put the conftest.py
in the tests
directory as wellbetter-van-82973
11/13/2023, 2:16 PMconftest.py
in that same directory as wellfast-photographer-12719
11/13/2023, 2:21 PMmodels
- tests
L conftest.py
L some_test.py
-some_code.py
and in my repo we're currently doing:
models
- tests
L conftest.py
L some_test.py
- code
L some_code.py
so similar to you. However, when you try to use pants to test only the code that has changed, you need to have specific dependencies from the test to the specific code files being tests. i.e. some_test.py -> some_code.py. That way, when you change some_code.py it will identify that it needs to run the some_test.py file as part of tests. To write that dependency, you have to put the test in the same folder as the code.better-van-82973
11/13/2023, 2:26 PMpython_test_utils()
python_tests()
`models/BUILD`:
python_sources()
Pants does dependency inference: https://blog.pantsbuild.org/why-dependency-inference/
so you shouldn’t have to explicitly specify the dependency between some_test.py
and some_code.py
happy-kitchen-89482
11/13/2023, 2:26 PMhappy-kitchen-89482
11/13/2023, 2:27 PMsrc/python/bar/foo_test.py
tests src/python/bar/foo.py
and so onhappy-kitchen-89482
11/13/2023, 2:27 PMhappy-kitchen-89482
11/13/2023, 2:28 PMhappy-kitchen-89482
11/13/2023, 2:28 PMhappy-kitchen-89482
11/13/2023, 2:29 PMsrc/python/bar
or src/python
, depending on what scope it's supposed to apply tofast-photographer-12719
11/13/2023, 2:29 PMhappy-kitchen-89482
11/13/2023, 2:30 PMhappy-kitchen-89482
11/13/2023, 2:30 PMpants dependencies --transitive
happy-kitchen-89482
11/13/2023, 2:31 PMpants paths
fast-photographer-12719
11/13/2023, 2:33 PMfast-photographer-12719
11/13/2023, 2:33 PMfresh-cat-90827
11/13/2023, 2:44 PMfast-photographer-12719
11/13/2023, 2:57 PMpants --changed-since=HEAD --changed-dependents=transitive test
When i removed the --changed-dependents
it runs nothing as i'd expect. I'll try looking through the dependencies to see if there's anything strange in there but they looked correct to me earlier.fresh-cat-90827
11/13/2023, 2:58 PMgit diff
, are you sure you don't have any changes in the working tree? 😕fast-photographer-12719
11/13/2023, 2:58 PM(base3.10) matt@DGX-2:~/mlcore$ git diff
(base3.10) matt@DGX-2:~/mlcore$
fresh-cat-90827
11/13/2023, 3:00 PMfresh-cat-90827
11/13/2023, 3:00 PMpants --changed-since=HEAD --changed-dependents=transitive list
goal?fast-photographer-12719
11/13/2023, 3:01 PMfast-photographer-12719
11/13/2023, 3:02 PMfresh-cat-90827
11/13/2023, 3:20 PMpants dependents --transitive <your-python-test-module.py>
on random files to see what kind of things they depend onfast-photographer-12719
11/13/2023, 3:44 PMpants --changed-since=HEAD --changed-dependents=transitive list
and i see pretty much every file in the repo. Now when remove teh transitvie, i see only one: the default lockfile.
py39) matt@DGX-2:~/mlcore$ pants --changed-since=HEAD list
3rdparty/python/default.lock:_default-resolve_lockfile
I guess that's because the lockfile is younger than the commit perhaps? When i generate the lockfile on the cheeshop repo and run the list or test again, it runs the tests every time. So i guess there is something about the lockfile's age?fast-photographer-12719
11/13/2023, 3:50 PMpants --changed-since=HEAD --changed-dependents=transitive list
and you will see no targets
3. pants generate-lockfiles
4. repeat step 2 but now you will see lots of dependencies. Which means it will try to run all the testsfast-photographer-12719
11/13/2023, 3:57 PMfresh-cat-90827
11/13/2023, 4:08 PMfast-photographer-12719
11/13/2023, 4:09 PMfresh-cat-90827
11/13/2023, 4:09 PMpants generate-lockfiles
it may be not obvious, but this command may produce a different output on subsequent runs even with no source code changes because it fetches the data from the external resources and pip may resolve the 3rd party dependencies differentlyfresh-cat-90827
11/13/2023, 4:11 PMthe lockfile isn't different thoughoh I see, let me try to repro locally and explore!
fast-photographer-12719
11/13/2023, 4:11 PMchanged-since
however if i was using this in CI for example, then i generate the lockfile before teh tests, so it would always identify the lockfile as newer i think?fresh-cat-90827
11/13/2023, 4:13 PMfast-photographer-12719
11/13/2023, 4:16 PMfresh-cat-90827
11/13/2023, 4:20 PMtest
and other goals would normally use the lockfile that is already in the repo, they don't have to generate any.fresh-cat-90827
11/13/2023, 4:20 PMfast-photographer-12719
11/13/2023, 4:23 PMfresh-cat-90827
11/13/2023, 4:23 PMfresh-cat-90827
11/13/2023, 4:24 PMfast-photographer-12719
11/13/2023, 4:25 PMfresh-cat-90827
11/13/2023, 4:28 PMgo.sum
file in Golang world. So your go.mod
is Python requirements file with direct dependencies (optionally, with exact versions, but most often not) and go.sum
is the resolved list of requirements with transitively pinned dependencies (with checksums)fresh-cat-90827
11/13/2023, 4:29 PMfresh-cat-90827
11/13/2023, 4:30 PMfast-photographer-12719
11/13/2023, 4:39 PMhappy-kitchen-89482
11/13/2023, 4:56 PMfast-photographer-12719
11/16/2023, 11:48 AMhappy-kitchen-89482
11/18/2023, 1:38 AMsources=
that are below it in the filesystem tree, but you can have a separate BUILD file that has a resources()
or files()
target that owns those sources, and then the first target can have an explicit dependency on that target.happy-kitchen-89482
11/18/2023, 1:41 AM.git
(and all other root-level dirs starting with a dot) by default (see https://www.pantsbuild.org/docs/reference-global#pants_ignore), so you'll have to futz with that optionhappy-kitchen-89482
11/18/2023, 1:41 AMhappy-kitchen-89482
11/18/2023, 1:41 AMhappy-kitchen-89482
11/18/2023, 1:42 AM