how do I suppose to add pytest.ini?
# general
b
how do I suppose to add pytest.ini?
h
Hello! Where is this BUILD file located? Is it at
a/b/tests/BUILD
? If so,
sources
should be
*
rather than
a/b/tests/*
. Also, use
**/*
if you want to have a recursive glob, although, this is discouraged because it means you won’t get as fine grained of caching. See https://www.pantsbuild.org/build_files.html#target-granularity
b
BUILD is located at the same directory as
a
h
If it is in
a
, then you would want your glob to be something like
b/tests/pytest.ini
or
b/**/*
Let me know if that works. I’m not sure if Pytest will pick it up, and we might need to add an option like
--pytest-config
that you can set globally, like we have
--black-config
and
--isort-config
.
h
I think "same directory as a" means that
sources=["a/b/tests/*"]
is right
The BUILD file is a sibling of
a
@hundreds-father-404 IIRC Pytest does autodiscovery of pytest.ini, and there can be many of them (they apply from their directory downwards).
👍 1
So I'm not sure what's issuing that ERROR that @bland-horse-61839 is seeing
I would have thought pytest would silently ignore a missing pytest.ini because it doesn't know it's missing, it would just fail to discover it.
@bland-horse-61839 Do you have any config that is explicitly pointing to that pytest.ini?
The
[]
in
no name <path to pytest.ini> in any of []
is interesting
b
pants-test.tar
I have created very reduced version of my project which contains all the relevant files for this. Just run
pants test a:tests
to see the results. I'm using pants 1.25.0
On this project all I have is an
a
folder and
a/tests
folder
The errors are:
ERROR: not found: /home/udi/pants-test/.pants.d/pyprep/sources/fad50c981db7799628408665542675aafc6f104b-DefaultFingerprintStrategy_b320b3b2f022/tests/pytest.ini
(no name '/home/udi/pants-test/.pants.d/pyprep/sources/fad50c981db7799628408665542675aafc6f104b-DefaultFingerprintStrategy_b320b3b2f022/tests/pytest.ini' in any of [])
Something I have just noticed - this problem isn't specific for
pytest.ini
file, but it happens for every file that doesn't ends with
.py
. For an example if you will create
a/test/aaa
the same problem will occuer for
aaa
file. BUT it you will change the file name from
aaa
to
aaa.py
the problem will go away @hundreds-father-404 @happy-kitchen-89482
h
Interesting. Could you try putting
pytest.ini
in a different target type please?
Copy code
# a/b/tests/BUILD
resources(
  name="pytest_ini",
  sources=["pytest.ini"],
)
Then, in whatever your test target is
Copy code
python_tests(
  name="whatever this was before",
  sources=["**/*.py"],
  dependencies=[
     "a/b/tests:pytest_ini",
  ],
)
If
resources
doesn’t work how you’d expect, try
files
b
@hundreds-father-404 Well, looks like pytest is no longer complaining about not finding pytest.ini, but it don't looks like it cares about it either - I have just put some random text in
pytest.ini
so pytest will complain it can't interpret and it doesn't do that
do you want me to upload an tar of the test project like before?
just to be clear, tried with
resources
and
files
. Same result for both
h
I'll take a look at that tarball
b
pants-test.tar
@happy-kitchen-89482
h
Looking now
@bland-horse-61839 do you have a
pants
runner script in that repo? I don't see one in the tarball
Which version of pants are you using?
b
no, i am pants which i was installed from pip as i was saying few messages ago - pants version 1.25.0
@happy-kitchen-89482
h
Did you see the installation instructions? https://www.pantsbuild.org/install.html#recommended-installation
b
@hundreds-father-404 Ok, the following tarball contains pants. Still got the same error
h
So far I've confirmed that this doesn't work on the v1 engine and does work as expected on the v2 engine.
Digging deeper
👍 1
b
when v2 will be released?
h
It's recently released and ready to use for Python (v2 in this context means the new engine, not Pants 2.x, sorry for the numbering confusion). I'd say it's beta quality right now, we're still ironing out some UX and performance issues here and there, but the functionality is fleshed out and includes,
test
,
binary
,
run
,
repl
,
setup-py
,
awslambda
,
fmt
,
lint
. So basically parity with v1, for Python, except for codegen (which is coming soon).
Happy to walk you through using it if you're interested in giving it a try!
❤️ 1
Has your repo been using pants v1 for a while? Or are you newly adopting it?
b
great 😃 actually we are trying pants for our monorepo, we don't use it yet. i will love to give it a try 😃 how do i start?
❤️ 2
👖 1
h
Great!
So, the documentation here: https://pants.readme.io/, is still a work in progress (but I am literally updating it every day). The best resources are to look at this example repo : https://github.com/pantsbuild/example-python/ and the docsite
And I can answer questions here
Walking through the Getting Started section in that docsite is probably a good way to, er, get started...
Together with looking at the examples in that repo. And if anything is unclear in the docs, or doesn't work as expected, ping me here!
Or in fact I may start a channel for this
💯 1
b
great i will check it! BTW if I may, I still want to be updated about the pytest.ini thing 😃