TRF042
A tokenizer test must exercise the shared TokenizerTesterMixin suite.
| Default | Enabled |
| Scope | Models added on or after 2026-06-20 |
| Source | mlinter/trf042.py |
| Show in terminal | mlinter --rule TRF042 |
What it does
In tests/models/*/test_tokenization_*.py, checks that the file defines a test class inheriting TokenizerTesterMixin. Only classes the test runner collects are considered — a TestCase base, or the *Test naming convention when the base is another model’s test class — so files whose only classes are helpers are skipped, and a helper mixing in the suite does not satisfy the rule on a real test class’s behalf. The violation is reported on the first test class that does not run the suite. Inheritance is followed through base classes defined in the same file and into another model’s tokenizer test imported by name, so a class deriving from one that already carries the mixin is satisfied; a base the tests tree cannot resolve never counts as carrying it. auto is allowlisted because test_tokenization_auto.py tests AutoTokenizer resolution rather than one model’s tokenizer. Ships with the file discovery widened to tests/models/**/test_tokenization_*.py, which affects which files the linter walks for every rule – existing rules all gate on the file-name prefix, so none of them see these files.
Why is this bad?
TokenizerTesterMixin is where encode/decode round-tripping, padding and truncation, special-token handling, added-token persistence, and save/load equivalence are actually checked. A tokenizer test that only asserts a couple of hand-written token id lists passes while the tokenizer is broken in every one of those dimensions, and the gap is invisible in review because the file looks like it has tests. Reviewers ask for the mixin by name on new tokenizers; five of the six tokenizer tests missing it predate 2026.
Example
-class AcmeTokenizationTest(unittest.TestCase):
+class AcmeTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
+ tokenizer_class = AcmeTokenizer
+ test_slow_tokenizer = True
Suppressing this rule
Add a # trf-ignore: TRF042 comment on the flagged line or the line directly above it. See Suppressing rules for whole-file directives and when a suppression is the wrong answer.
Allowlisted models
1 model are exempt from TRF042 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.
Show the 1 allowlisted model
auto
