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

wooden-thailand-8386

09/11/2020, 7:48 PM
Hey what would be a good pattern for shared fixtures for multiple tests? Right now I have a
tests
folder that branches into a similar structure as I have for my projects ands libs.. something like:
Copy code
tests/
  libs/
    libA/
    libB/
   projects/
    projectA/
    projectB/
and for libA and libB I might have a couple of fixtures that are basically the same. Should I create a “fixtures-lib” and use / put a fixtures folder under
tests
and reuse it or duplicate code?
h

hundreds-father-404

09/11/2020, 7:51 PM
cc @polite-garden-50641, who uses fixtures a lot with the Toolchain repo. Often, I’ve seen him use a
/fixtures
folder with test data, like sample JSON values. I think you can also put Pytest fixtures in a
conftest.py
. As soon as you can upgrade to 2.0, we added a
--python-infer-conftests
mechanism that will automatically infer a dependency on any
conftest.py
in the current directory and any ancestor directory In the meantime, you’d have to explicitly add the dependency. (Benjy is close to landing the proxy fixes: https://github.com/pantsbuild/pants/pull/10757)
❤️ 1
w

wooden-thailand-8386

09/11/2020, 7:54 PM
it’s looking a little bit “hacky” but I’m importing the fixtures inside the
conftest.py
something like:
Copy code
from shared_fixtures import stack_agent

stack_agent = stack_agent