In pants 2.13, is there a way to exclude `__init__...
# general
b
In pants 2.13, is there a way to exclude
__init__.py
files in the pants config instead of the BUILD files? Migrating from pants 1.30 and it seems like 2.13 wants to run every file through pytest, however we have plenty of
__init__.py
and
common.py
files which we don't want to make pytest attempt to execute. Was hoping to have a global config rather than have every BUILD file have a statement in the sources that tells it to ignore the names I mentioned
f
There is a
__defaults__
mechanism coming in 2.14 I believe.
Which will let you set default attributes for every target at and under the BUILD file where the
__defaults__
clause is located. You could set a different default
sources
attribute there.
h
Hello, what do you mean with this?
which we don't want to make pytest attempt to execute.
Pants no matter what includes init.py your files in the sandbox. whereas v1 did this weird and wrong thing of synthesizing files for you depending on https://www.pantsbuild.org/docs/reference-python-infer#init_files, Pants will also infer dependencies on any import statements inside those init files
b
So what happens in 2+ from my observation is pytest tries to execute whatever test may exist in the init.py but considers it failed since we don't put any tests in those. The rest of the tests work just fine, but pants marks the other test files as failed
I was hoping that something like
python_files
that pytest supports to tell pants/pytest to not try and execute tests for a file that doesn't match our pattern
h
Can you please run
./pants peek path/to/some/__init__.py
and show it here, for one of the problematic init files? I suspect that you have
__init__.py
included in the
sources
field for some
python_tests
target generator, which is a semantic error
I was hoping that something like python_files that pytest supports to tell pants/pytest to not try and execute tests for a file that doesn't match our pattern
that's what `python_source`/`python_sources`/`python_test_utils` are for (where the latter two are "target generators" for
python_source
)
b
Ah ok, I can work with putting that in the individual build files then, sounds like that's the only way to ignore those files. Was hoping to have a global option but that doesn't sound like that's the case. When I did the peek I saw that one of the init files would be pulled in and
skip_tests
was false, so that to me sounds like pants will execute tests on that specific file