Hey what would be a good pattern for shared fixtur...
# general
w
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
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
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