terraform-cdk
terraform-cdk copied to clipboard
PytestCollectionWarning raised in using cdktf.Testing static methods with Pytest
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
cdktf & Language Versions
Language: Python CDKTF Version: 0.12
Affected Resource(s)
Testing assertions
Debug Output
Expected Behavior
No warning
Actual Behavior
PytestCollectionWarning raised
Steps to Reproduce
Using any static method from cdktf.Testing within a pytest test suite
Important Factoids
To my understanding the issue causes no issues in terms of functionality, only an annoying warning.
The issue stems from the the naming of Testing as pytest attempts to collect the class as a test class since it's name is prefixed with Test.
References
Stack Overflow post describing the issue and a post in the thread with a potential simple fix
- #0000
Just gave the the accepted answer at StackOverflow (__test__ = False) a quick test and unfortunately JSII does not allow properties starting with an underscore to be exposed to the other languages. So there's no simple way to get __test__ = False included in the generated Testing class in Python.
Maybe there is another way to get __test__ into the __dict__ property of the Testing class, but I couldn't quickly find it.
Meanwhile to suppress warning you can create pytest.ini and add
[pytest]
filterwarnings =
ignore:::.*.cdktf:11850

Thanks, @nlucansk
With cdktf 0.16.3, I had to update the above to be: ignore:::.*.cdktf:13637
Is the Testing class static? If yes, can it not just be converted into a module, say cdktf.testing?