Skip to main content

Command Palette

Search for a command to run...

unittest param order is the opposite of Jest

Published
1 min read
F

React, Django and SQL developer at Forma.ai

which is the opposite order for Jestexpect(myVar).toBe(42)

assumes the first is expected, second is actual in the error message.

self.assertEqual(expected, actual)
self.assertEqual(42, my_var)

PyCharm even displays Expected and Actual

Failure
Expected : 42
Actual   : 4.2

Whereas Jest has the reverse order expect(myVar).toBe(42)

Why

It's a JUnit thing (which unittest is based off)

https://stackoverflow.com/questions/2404978/why-are-assertequals-parameters-in-the-order-expected-actual/57059952#57059952

Pytest

Pytest doesn't care about order

There's even a setting in PyCharm to swap the order