Shorten pytest's test names
I noticed that the unittest pipeline was failing. I opened up the logs and saw a wall of text that took about 20 pages to scroll through to see what was failing. It turned out to be an Assert
failure where the input wasn't raising an exception
.
The parametrized test case failure was 1MB byte
array that needed to raise the exception.
Parameterize tests need ids
for each test, which the test case's arguments generate.
Numbers, strings, booleans and None will have their usual string representation used in the test ID. For other objects, pytest will make a string based on the argument name:
Luckily, parametrize
's ids
keyword argument takes an iterable of strings for which you can override this default behavior.
Good bye wall of text!
Reference
Subscribe to my newsletter
Read articles from Danny Crasto directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Danny Crasto
Danny Crasto
I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae