terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

PytestCollectionWarning raised in using cdktf.Testing static methods with Pytest

Open Maed223 opened this issue 2 years ago • 4 comments

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

View here

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

Maed223 avatar Aug 04 '22 19:08 Maed223

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.

ansgarm avatar Aug 09 '22 12:08 ansgarm

Meanwhile to suppress warning you can create pytest.ini and add

[pytest]
filterwarnings =
    ignore:::.*.cdktf:11850

image

nlucansk avatar Aug 17 '22 11:08 nlucansk

Thanks, @nlucansk

With cdktf 0.16.3, I had to update the above to be: ignore:::.*.cdktf:13637

gtback avatar Jun 20 '23 19:06 gtback

Is the Testing class static? If yes, can it not just be converted into a module, say cdktf.testing?

martimors avatar Sep 01 '23 08:09 martimors