🚀 feature request
Relevant Rules
py_test
Description
There is a common pitfall when using py_test where if the user forgets to add any executable statements to their module, it will silently pass without actually running any tests. For example, the user might incorrectly assume that py_test automatically invokes the pytest or unittest runner, see https://www.youtube.com/watch?v=5OjeeNHiKw4. In my company's repo, I found a surprising number of examples of this.
We can catch this by adding a validation action to py_test that runs a static analysis of the main module and fails if the body only contains class and method definitions.
This would technically be a breaking change, so it should be gated behind a config setting with a default of false, but could be flipped for rules_python 3.0.
Describe the solution you'd like
Introduce a validation action in the critical path of py_test that runs the above static check using ast. Builds of py_test rules will fail if they do not meet this test, and will print a descriptive error.
Describe alternatives you've considered
Do nothing, and let users handle this with a custom aspect that does the same thing.
🚀 feature request
Relevant Rules
py_test
Description
There is a common pitfall when using py_test where if the user forgets to add any executable statements to their module, it will silently pass without actually running any tests. For example, the user might incorrectly assume that
py_testautomatically invokes thepytestorunittestrunner, see https://www.youtube.com/watch?v=5OjeeNHiKw4. In my company's repo, I found a surprising number of examples of this.We can catch this by adding a validation action to
py_testthat runs a static analysis of themainmodule and fails if the body only contains class and method definitions.This would technically be a breaking change, so it should be gated behind a config setting with a default of false, but could be flipped for rules_python 3.0.
Describe the solution you'd like
Introduce a validation action in the critical path of
py_testthat runs the above static check usingast. Builds ofpy_testrules will fail if they do not meet this test, and will print a descriptive error.Describe alternatives you've considered
Do nothing, and let users handle this with a custom aspect that does the same thing.