Working with conftest.py
fixtures in a Python monorepo
#17762
-
In the layout of a monorepo
when running tests in From the docs:
This means that when making changes to the root
However, it seems fair that all subprojects may want to use a generic fixture from the root Importing individual fixtures (so that you would split the root
I see usage of
in various repositories, but this doesn't work well with Pants dependency inference (as there are no What kind of approach have you decided to go with? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
If you turn on string import matching, this would work, FYI (we do it at our org) |
Beta Was this translation helpful? Give feedback.
-
I don't think there's a one-size-fits-all answer. I think it's really a crossroads of choices you and your team get to decide on. Things like remote caching and test layout affect the choices you'll make. However, my general rule of thumb for |
Beta Was this translation helpful? Give feedback.
-
I actually prefer your approach, that's what I do in my repo. The best way I've found (forget where I found this) is to create a top level conftest that imports the the subdirectory conftests as plugins. This is the code I use:
This way would help achieve what you're looking for because you would have a top level conftest that would only hold fixtures that are truly applicable to the whole repo, then you could define fixtures in the sub-conftest files, which would work in any pytest run. |
Beta Was this translation helpful? Give feedback.
If you turn on string import matching, this would work, FYI (we do it at our org)