PyJest — a simple implementation of Jest via python
Look at this python — unittest code:
And at this js-Jest code:
Why can’t it be as simple as that in python too?
I’ve written a simplified implementation of jest in python to explore this direction in testing in python.
Well, it can look like that:
To do so, we should start with the “expect” function, that returns an object, with the “jest” methods:
The tester class we want to implement is the “pyJest” this is the lean version of it:
The tester logger is an abstract class with the following abstract methods: write, _success_writer, and _failure_writer, and one router method —conditional_logger_writer :
In other words, the “expect” method returns an object with the expression as an attribute and a collection of methods that can access the expression.
In conclusion, writing tests in python can be as enjoyable as in JS, with a simple one-time effort of implementing the jest package in python. I hope this simple implementation example will inspire some of you to try this yourself,