Configure Pytest discovery to ignore class name

后端 未结 5 928
生来不讨喜
生来不讨喜 2021-01-11 14:16

Pytest\'s default discovery rules will import all Class starting with Test that do not have an __init__(). I have a situation where this causes an

5条回答
  •  一整个雨季
    2021-01-11 14:53

    The configuration options seem to only be prefixes or globs, so I don't think you can exclude a specific file name: https://pytest.org/latest/customize.html#confval-python_classes

    I think renaming your class (MyTestimonialFactory) or moving it outside of the discovery path would be the easy fix here.

    That said, I still think you could use one of the collection hooks to skip or remove that class during collection. Perhaps pytest_pycollect_makeitem, as described here: https://docs.pytest.org/en/latest/writing_plugins.html#collection-hooks

提交回复
热议问题