It’s just a fact of life, as code grows eventually you will need to start adding mocks to your test suite. What started as a cute little two class project is now talking to external services and you cannot test it comfortably anymore.

That’s why Python ships with unittest.mock, a powerful part of the standard library for stubbing dependencies and mocking side effects.

However, unittest.mock is not particularly intuitive.

I’ve found myself many times wondering why my go-to recipe does not work for a particular case, so I’ve put together this cheatsheet to help myself and others get mocks working…


This is the second part of a two part series on coroutine patterns in asyncio, to fully benefit from this article please read the first installment: Asyncio Coroutine Patterns: Beyond await

In the first part of this series we concluded that asyncio is awesome, coroutines are awesome and our code is awesome. But sometimes the outside world is not as awesome and we have to deal with it.

Now, for this second part of the series, I’ll run over the options asyncio gives us to handle errors when using these patterns as well as cancelling tasks so as to make…


Asyncio, the concurrent Python programmer’s dream, write borderline synchronous code and let Python work out the rest, it’s import antigravity all over again…

Except it isn’t quite there yet, concurrent programming is hard and while coroutines allow us to avoid callback hell it can only get you so far, you still need to think about creating tasks, retrieving results and graceful handling of errors. Sad face.

Good news is all of that is possible in asyncio. Bad news is it’s not always immediately obvious what wrong and how to fix it. …


I remember distinctly the moment where I thought, “Wow, that’s slow, I bet if could parallelize these calls it would just fly!” and then, about three days later, I looked at my code and just didn’t recognize it in the unreadable mash up of calls to threading and process library functions in front of me.

Then I found asyncio, and everything changed.

If you don’t know, asyncio is the new concurrency module introduced in Python 3.4. …


Hey, Django dev, come here for a sec!

I heard you’re on Rails now, looking for some quick answers?

Yeah, I’m your man, got them right here.

ORM

I’m gonna be straight with you, Django’s ORM is nicer than Rails’s.

There, I said it. Now that it’s out of my system let’s find some models:

# One model
Dj> Model.objects.get(id=1)
Ra> Model.find(id: 1) # when using a PK
Ra> Model.find_by(name: "A name") # when using any other field

So far so good, Rails uses find when looking up by ID, find_by when looking up by anything else.

# Single record filtered…


You are seasoned Django developer.

You are master of the models. Ruler of the views. King of the templates.

But fate has brought you to Rails now, and you feel clumsy, slow, googling every step of the way. You’re asking yourself how do I Django in Rails?

I’ve been there and it’s not fun. The good thing is that Rails has been used and loved for a long time, there’s a lot of really nice resources out there. My two favourites are the official Rails guides and API documentation.

But I’ve found there’s a lot differences in naming and workflow…


Wait, we’ve launched? Nice!

It’s been busy around here, real people are making real Stacks and we’ve been at our best to keep up. A whooping total of 600+ invite requests, 344 users and a nice round grand total of 150 Stacks!

Slowly but surely we’ve been bug fixing and tweaking the site, responding to the (mostly) lovely feedback from our cherished Stackers, but we want more! We’ve sent a new set of private invites and we’re rolling out a new system that will allow you to invite other people which should be exciting.

It’s been incredibly encouraging to watch…

Yeray Diaz

Freelance Software Engineer, London, UK. Twitter: @yera_ee

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store