Update to more general case: How can I prevent a PytestCollectionWarning when testing a Class Testament via pytest? Simple example for testament.py:
class Testament():
def __init__(self, name):
self.name = name
def check(self):
return True
And the test_testament.py
from testament.testament import Testament
def test_send():
testament = Testament("Paul")
assert testament.check()
This creates a PytestCollectionWarning when run with pytest. Is there a way to suppress this warning for the imported module without turning all warnings off?
You can set a __test__ = False
attribute in classes that pytest should ignore:
class Testament:
__test__ = False
You can run pytest with the following flag:
-W ignore::pytest.PytestCollectionWarning
This is just the "normal" warning filter for python, according to the documentation:
Both -W command-line option and filterwarnings ini option are based on Python’s own -W option and warnings.simplefilter
You can define the python_classes option in your config file to change from default Test*
to e.g. *Tests
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With