Where to place stub classes that are used to mock by several test packages? #10038
-
I have a package called Now, I have a few other packages that use the classes from package As the stub classes are exactly the same for each and every package, it feels wrong to copy + paste them and end up with a lot of duplicate code. It would make more sense to ship these stub classes with package Example of that this causes a lot of duplicate code when added for each test module: https://bpa.st/CKHQ However, I don't know where to place these stub classes. I can't find any guidelines on this or other packages that have done the same. Someone on IRC said:
... but I'm not sure if this is the right answer. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
To add some more context to what I said in IRC: It's somewhat common for bigger projects to ship some kind of I don't see a reason why such a sub-package couldn't also contain mocks to use. Another approach (which I don't have an example of off-hand) is to ship a "fake backend" or "test backend" if some code already has multiple configurable backends to use for something. Another approach you could take is to write a pytest plugin (say, |
Beta Was this translation helpful? Give feedback.
To add some more context to what I said in IRC: It's somewhat common for bigger projects to ship some kind of
testing
/test
/test.utils
/ ... sub-package:I don't see a reason why such a sub-package couldn't also contain mocks to use. Another approach (which I don't have an example of off-hand) is to ship a "fake backend" or "test backend" if some code already has multiple configurable backends to use for something.
Another approach you could take is to write a pytest plugin (say,
pytest-A
in your example) which is installable independently fromA
and provides the same functionality via pytest fixtures. If we're just talking about some mock classes, that se…