Hello, I am new to Pants and converting my nox pro...
# general
t
Hello, I am new to Pants and converting my nox project to Pant 🙂 , I am facing a problem when running
pytest-bdd
, My feature files are not accessible, and I have tried as
python_test_utils
and
files
and included them in dependencies for python_test, still no luck,. I am facing file not found issue for
/private/tmp/.tmpBDSdib/tests/bdd/features/integration_instance.feature
I am sure its very small thing I am missing, hope some one can help me here.
1
r
I think you're experiencing a same issue like mine: placing non-source/non-test files in the pex environment for pytest...
Tried things like this, but no success yet..
b
@tall-jelly-41236 Can you post your BUILD file?
Also
runtime_package_dependencies
is for package-able things, for assets you'll just use
dependencies
👍 1
h
I think you'll need a target like
files(name="features", sources=["*.feature"])
and then have the
python_tests()
target explicitly depend on that target.
(I took a quick look at the feature loading code in pytest-bdd, and it directly accesses the filesystem using
os
, rather than loading them as a resource via
pkgutil
, so a
files()
target is the way to go)
b
@happy-kitchen-89482 IIUC for
test
the distinction between the two is a bit arbitrary as the file should be on disk in the same place either way. It matters more for packaged code. You do need the target either way though, and files is likely "more correct"
h
Yeah I guess that is correct since at test time the 1stparty sources are consumed as loose files
1
Still, files() is more conceptually apt I guess
1
b
(if you're relying on python asset inference, they're inferred differently. So that's the only semantic difference)
t
Copy code
python_requirements(
    name="connector-requirements.txt",
    source="requirements.txt",
)


python_sources(name="sources",
                dependencies=[
                "packages/connector-common:sources",
                "packages/connector-auth:sources",
                ":connector-requirements.txt"]
               )
files(
       name="features",
       sources=["tests/bdd/feature/*.feature"]
       )

python_test_utils(
    name="test_utils",
    sources=["tests/bdd/test/conftest.py"],
)

python_tests (
    name="tests",
    dependencies=[":sources",":features"],
    sources=["tests/**/test_*.py"]

)
@happy-kitchen-89482 your right this is using
os.
option instead of
files
b
Is there a reason you're manually declaring fields/dependencies instead of relying on the default/inference?
E.g. the default for
python_test_utils
or inference for which sources your tests depend on?
t
i can remove 🙂 i was trying all options 😞 to fix it
👍 1
h
So does this not work as-is?
With the
files()
target etc?
b
Your
BUILD
looks right, so next step would be to run your test file with
--no-process-cleanup
(e.g.
./pants --no-process-cleanup test path/to/test.py
). It will log and leak the sandbox directory, then you can poke and ensure the files are there in the right place
h
That
":features"
dependency should put all the features files in the sandbox that pytest runs in
👀 1
Yep, what @bitter-ability-32190 said 🙂
b
(Also when you remove your defaults/dependencies. You can use goals like
peek
and
dependencies
to ensure Pants is still doing the right thing)
h
That will let you look inside the sandbox and see if all the files are in the right place
t
--no-process-cleanup
should give me the hint on the folder structure to fix my path
let me try that
adding that i was able to see the folder structure for the process. but i did not see my .features with
files
option.
h
Odd. Are you able to put up a tiny example repo that demonstrates the issue?
b
Only thing I can think of is either the glob is wrong (you can run ,
./pants list
to see if it lists those files) or the plugin expects them at a different path
t
Copy code
./pants list packages/connector-apis: | grep "features"
packages/connector-apis:features
i can see target, but not the actual .feature files
b
They're on disk and not gitignored?
t
yes they are on the disk
b
Are they gitignored? If not then this is weird and you'll probably want to provide a minimally reproducing example
t
feature files are not part of
git ignored
Copy code
git status trigger_process_metadata.feature 
On branch develop
Your branch is up to date with 'origin/develop'.

nothing to commit, working tree clean
i figures the problem.
👀 2
the folder was
features
not
feature
that
s
caused this confusion
i was able to connect load feature files via
files
target and including in the dependencies
b
You should've gotten a warning at some point that the glob didn't match any files. But then once you miss it, the code isn't run again because the value it produced is cached
t
thanks for the help @bitter-ability-32190 @happy-kitchen-89482 sorry, it was simple problem on my side 😞
h
Bingo! Glad it's working now!