https://pantsbuild.org/ logo
#general
Title
# general
t

tall-jelly-41236

05/15/2022, 4:01 AM
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

rhythmic-morning-87313

05/15/2022, 9:22 AM
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

bitter-ability-32190

05/15/2022, 11:21 AM
@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

happy-kitchen-89482

05/15/2022, 2:48 PM
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

bitter-ability-32190

05/15/2022, 2:52 PM
@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

happy-kitchen-89482

05/15/2022, 2:54 PM
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

bitter-ability-32190

05/15/2022, 2:55 PM
(if you're relying on python asset inference, they're inferred differently. So that's the only semantic difference)
t

tall-jelly-41236

05/15/2022, 3:49 PM
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

bitter-ability-32190

05/15/2022, 3:49 PM
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

tall-jelly-41236

05/15/2022, 3:51 PM
i can remove 🙂 i was trying all options 😞 to fix it
👍 1
h

happy-kitchen-89482

05/15/2022, 3:51 PM
So does this not work as-is?
With the
files()
target etc?
b

bitter-ability-32190

05/15/2022, 3:52 PM
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

happy-kitchen-89482

05/15/2022, 3:52 PM
That
":features"
dependency should put all the features files in the sandbox that pytest runs in
👀 1
Yep, what @bitter-ability-32190 said 🙂
b

bitter-ability-32190

05/15/2022, 3:53 PM
(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

happy-kitchen-89482

05/15/2022, 3:53 PM
That will let you look inside the sandbox and see if all the files are in the right place
t

tall-jelly-41236

05/15/2022, 3:53 PM
--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

happy-kitchen-89482

05/15/2022, 7:45 PM
Odd. Are you able to put up a tiny example repo that demonstrates the issue?
b

bitter-ability-32190

05/15/2022, 7:48 PM
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

tall-jelly-41236

05/15/2022, 8:34 PM
Copy code
./pants list packages/connector-apis: | grep "features"
packages/connector-apis:features
i can see target, but not the actual .feature files
b

bitter-ability-32190

05/15/2022, 8:35 PM
They're on disk and not gitignored?
t

tall-jelly-41236

05/15/2022, 8:35 PM
yes they are on the disk
b

bitter-ability-32190

05/15/2022, 8:38 PM
Are they gitignored? If not then this is weird and you'll probably want to provide a minimally reproducing example
t

tall-jelly-41236

05/15/2022, 8:42 PM
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

bitter-ability-32190

05/15/2022, 8:48 PM
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

tall-jelly-41236

05/15/2022, 8:50 PM
thanks for the help @bitter-ability-32190 @happy-kitchen-89482 sorry, it was simple problem on my side 😞
h

happy-kitchen-89482

05/15/2022, 9:57 PM
Bingo! Glad it's working now!