Mocket is alive and is fighting with us
It’s HTTPretty, vcrpy and much more
It’s been a while ago, when Andrea and I decided to write Mocket and present it at EuroPython 2013.
It was something we had in mind for a while, a lot of fun during the night before our talk, for sure one of the best hacks I’ve done in my career.
We also had some plans, and one of the new-come user, back to August 2013, had something similar in his mind when he tried to contribute to the project. We’ve never followed it up, and that was a shame.
Andrea started his new life as dad, and the same project in which we really believed for a while, suddenly was not fun anymore.
That said, Mocket was the module we were relying on when we had to mock HTTP in my previous company, so I kept maintaining it in terms of bug-fixing, together with another former and present colleague, Oscar.
In Q4/2015 I moved to Berlin. Mocket is still behind the scenes of our Python test suite here at Planet Germany, and the big news is that I am back at contributing to it. Because it’s fun and it worths the time spent on it.
for all kinds of socket animals, web-clients included
What are the main features?
- It’s a framework, actually a socket mock framework, and the proof of its reliability as framework is that both the HTTP mocking module (à la HTTPretty) and the basic Redis mock have been implemented using Mocket, and nothing more than that.
It mocks the socket module, so you do not have to worry about anything else than the actual code you need. No fancy client mocks, please.
It’s main goal is providing a way to help testing Python clients that speak the socket language. See the MocketToy example for something socket-ish.
- It has SSL support, and of course HTTPS if we talk about its HTTP mock.
- It works well with others (e.g. pytest fixtures is one example, pook is another).
- It supports PyPy, gevent and asyncio/aiohttp.
- It dumps (as JSON files) everything that calls the sendall function on a true socket (recording functionality à la vcrpy).
- It strongly supports Python 3, since the very beginning. And yes, it’s definitely a big feature (ask HTTPretty users to better understand what does “supporting Py3” mean).
- Its APIs never changed. Frameworks should care about backward compatibility, and Mocket take it seriously.
- ~100% test coverage. Yes, that’s another important feature.
- UPDATE (29/08/2017) HTTPS is fully supported even on
asyncio
.
Did I mention how good is its Python 3 support?
Mocket 1.7 (with the new recording functionality) has just been shipped.
Let’s fire a pip install mocket
.
That’s all — for now — folks.
P.S.: I know, documentation still sucks. That’s my goal for the next weeks, and a blog-post will follow soon with a demonstration of its main features.