Open jarshwah opened 5 months ago
Currently no, but I wouldn't be opposed to adding a global flag in libcst.testing
that gets set to True
by the generated test methods, similar to PEP484's typing.TYPE_CHECKING
.
If you're interested in contributing this, I'd probably suggest something like libcst.testing.RULE_TESTING
as the name, and toggling the flag in the setUp/tearDown methods of LintRuleTestCase
.
I'd like to be able to detect when a LintRule is being run under test. I know it's possible to use the FilePathProvider to detect if the filename is
valid.py
orinvalid.py
but that can lead to false positives. Here's a full example of a rule I'm [re]implementing below.From within the rule, I want to check that we're linting an
__init__.py
file, so use the FilePathProvider to retrieve that information. Unfortunately unit tests will fail unless we also allow-through tests.Is there a better way to detect if we're running under test?