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 the file defines a collected test class inheriting TokenizerTesterMixin. Only classes the runner collects count – a TestCase base, or the *Test naming convention when the base is another model’s test class – so helper-only files are skipped, and a helper mixing in the suite does not satisfy the rule for a real test class. Inheritance is followed through bases in the same file and into another model’s tokenizer test imported by name; an unresolvable base never counts. Reported on the first test class that does not run the suite. auto is allowlisted: test_tokenization_auto.py tests AutoTokenizer resolution, not a tokenizer.
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 test that only asserts a few hand-written token id lists passes while the tokenizer is broken in every one of them, and still looks tested in review.
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
