DjangoCon Europe happened last month and we live tweeted the two workshops that we attended. Here they are

Property Based Testing Using Hypothesis

Many people would be familiar with unit testing tools like the JUnit inspired unittest library that is a part of the python standard library and the ever popular pytest library.

Less known is the technique of property based testing. We will do a more detailed writeup on property based testing in the future, but the concept is something like this:

You describe the property that your function should have. For example if we are building a sqrt function and get an output out = sqrt(in) then the property in == out * out must hold. If there is an input where this property is violated, then we have a bug.

The testing tool then generates a large number of sample inputs and validates the property for those inputs. This way you might catch some edge cases that you didn't think to test.

For python, the Hypothesis tool is very popular for doing this type of property based testing, and this workshop went through all the basics of using Hypothesis.

Check out our tweet thread for some examples of Hypothesis in action as well as links to the workshop material if you want to give it a try yourself

Building GraphQL API in Python using Strawberry

If you have been following along the buzz over the last few years then you probably know that GraphQL has been gaining quite a bit of traction in the web development space. For those not aware, GraphQL is an alternative way to do HTTP APIs compared to the traditional REST API. Developed by Meta, it allows the client to send complex queries in a single request to the backend server.

Of course, the backend server needs to do all the work of validating the input, performing the queries and returning the data in the requested format. This is where frameworks come into the picture. Strawberry is a GraphQL framework for python that does all this work for us.

Our twitter thread covers the workshop and should give you an idea of Strawberry. As before, if you are interested in trying it out yourself, links to the workshop materials are at the end of the thread. Check it out