Transactional Job Queues and the Two Generals’ Problem
Our worst outage in a decade of running Hypothesis, and how we made sure it never happened again.
I blog, you blog, weblog.
Our worst outage in a decade of running Hypothesis, and how we made sure it never happened again.
The simplest way to integrate Ruff’s Python code formatter into Vim, no plugins or language servers needed. The same technique can also be used to integrate any command line formatter, for any file type.
How to get the text editor Helix working with Python language servers and virtual environments. Plus a guide to Helix’s LSP -based features.
Many people use third-party Vim plugin managers like vim-plug, Vundle, Pathogen, etc. I recommend just using the built-in package manager that was introduced in Vim 8.0 (released in 2016). Here’s a quick how-to…
My advice for using Bitwarden safely, securely and reliably.
A quick tutorial for making a GPG -encrypted backup of your Bitwarden vault using pass .
Todo.txt is a bash script for managing a todo list in a plain text todo.txt file: $ todo.sh add Go grocery shopping 1 Go grocery shopping TODO: 1 added. $ todo.sh add Feed the cat 2 Feed the cat TODO: 2 added. $ todo.sh add Feed the dog …
A simple way to use GitHub Actions to build your Python package, bump the version number, and publish it to GitHub releases and PyPI.org all with a single click of a button in the web interface.
My guide to using the open source backup program restic to back up your files to Backblaze B2 cloud storage.
isync is a command line application that can synchronize a remote IMAP account (like a Fastmail or Gmail account) with local maildirs. This post will show you how to use isync to make a local backup of your Fastmail and Gmail accounts.
How to toggle between light-background and dark-background themes in tmux.
tmux’s default key sequence to enter copy mode and begin a search of the terminal history/scrollback is pretty awkward: Ctrl + b [ Ctrl + r if you’re using the default emacs-style copy mode bindings, or Ctrl + b [ ? if you’re using the vim-style bindings. Browsers use much easier shortcuts …
Make tmux tabs (“windows”) look more like browser tabs, and control them using the same keyboard shortcuts that you’re used to from browsers and other apps.
To list all current key bindings, including any custom bindings you’ve added and bindings added by plugins: Ctrl + b ? tmux list-keys or tmux lsk in a shell inside tmux list-keys or lsk at tmux’s command prompt ( Ctrl + b : ) The bind-key and unbind-key commands (aliases bind and unbind ) change …
How to use tmux’s set and show commands to set and query tmux config settings (“options”).
How to make copy and paste in tmux work the same as in other apps, using the system clipboard and primary selection.
vim-indent-object is a great Vim plugin that adds an i text object for an indented block of text, very useful in Python! vii selects all lines at the same indentation level as the current line. For example just the body of a method and not the method signature or any …
Vim has a comprehensive built-in manual. Unfortunately you need some help to know how to use the help. This post is a quick reference and tutorial for Vim’s :help files. See also :help opens Vim’s “main help file” ( help.txt ). There’s a short tutorial on how to …
Using the commentary.vim plugin to learn about Vim’s operators, motions and text objects.
GitHub Pages-compatible breadcrumbs for Jekyll.
My Liquid templating crash course, including Jekyll- and GitHub Pages-specific details.
It isn’t wonderfully well documented in Python that the builtin Exception class takes any number of positional arguments (pargs) and uses them to provide __str__() and __repr__() methods and pickling support. If you understand how Exception ‘ s pargs work then you can use it as a base class correctly …
Slides from a code design workshop for our Python, Pyramid web apps at Hypothesis.
Automate all of your Python project’s tasks with a succinct tox.ini file.
A comprehensive beginner’s introduction to tox.
How to configure an Ubuntu server to automatically keep itself up to date and send you email notifications.
Thunderbird actually has fairly complete keyboard shortcuts. The schema is all over the place, there’s little consistency to the design of the keyboard shortcuts, and frequently needed shortcuts are often out-of-the-way keys or difficult to hit multi-key combos, but the shortcuts do cover a lot of the app’s …
How to uniquely identify a PDF file, independent of the path or URL the file is currently at, and even after the file has been edited, using PDF .js’s “fingerprint” algorithm in JavaScript or Python.
This post covers one final technique that’s used in the Hypothesis tests: matcher objects . Matcher objects are a way to make complex assertions easier to read and write, make the intents of tests clearer, and reduce repetition between test methods. If you find yourself writing complex assertions that obscure …
The first post about mocks covered the basics of how to use Python’s mock library. The Problem with Mocks explained the dangers of using mocks and advanced features of the mock library that can be used to minimize those dangers. Returning to the topic of mocks, this post discusses …
Along with factories, parametrize and fixtures, one more thing that you’ll see a lot of in Hypothesis’s Python tests that you probably won’t know from non-test Python code are these things called mocks , which we’ll look at in this post. Mock “ Mock objects” are “are simulated …
In The Problem with Mocks we discussed some of the potential problems with mock-based tests. In this post we’ll discuss one of the most useful, and least problematic, ways that mock is used in the Hypothesis tests - patch() . patch One of the best uses for mocks in the Hypothesis …
This post covers mock.sentinel , a small bonus feature of the mock library that’s used fairly often in the Hypothesis tests. mock.sentinel is a handy object for creating unique, opaque, named objects for use in tests. You can access any attribute name on mock.sentinel and each one …
The first post about mocks covered the basics of how to use Python’s mock library . Using mocks has many advantages (which we’ll discuss in When and When Not to Use Mocks but they also have a downside: mocks can get out of sync with the real code that …
In the fixtures post we saw that usefixtures is a way for a test to use a fixture without taking it as an argument: @pytest . mark . usefixtures ( 'routes' ) def test_something (): ... The test doesn’t take the routes fixture as a method argument, and doesn’t need access to the routes …
In Basic pytest Fixtures we saw that fixtures are pytest’s alternative to setup() and teardown() methods or to test helper functions. This post will try to show that pytest fixtures are much more than just a more convenient alternative to helper functions, by explaining some of their more advanced …
This post covers the basics of pytest fixtures and how we use them at Hypothesis. A “test fixture” is some code that needs to be run in order to set things up for a test. When we created the objects that we needed to pass into the method we were …
This post covers testing multiple test cases at once using @pytest.mark.parametrize() . In Writing Simple Tests we tested the validate_url() function that validates the links that users add to their profiles. util.py also contains a validate_orcid() function for validating the ORCID ID ’s that users add to their …
The tests that we’ve written so far (see Writing Simple Python Unit Tests ) have been simple enough to fit in a single line of code: def test_validate_url_returns_an_http_url_unmodified (): assert validate_url ( 'https://github.com/jimsmith' ) == 'https://github.com/jimsmith' This line of code actually does three things: It creates a string …
Factories are a really quick and easy way to create realistic objects to use in your tests. For example if you’re testing the code for editing user accounts your tests may need some User objects to test with, if you’re testing groups you may need to create a …
Previously we tested that the validate_url() function returns the given URL if it’s a valid URL . If the given URL is not valid then validate_url() is supposed to raise a ValueError exception. To test this we need to use pytest.raises() . Here is a test that expects validate_url() to …
This post briefly covers some tools for debugging failing tests when using pytest. If looking at the traceback from a test failure isn’t enough there are a few tools to help debug a failing test: The --showlocals argument to pytest will print out the values of all local variables …
This post covers how to write your first, very simple Python unit tests. How the test code is organised The first thing you need to decide is where your new tests should go. Fortunately Hypothesis tests are organised in a very simple way. For every file in the the h …
This post covers running the tests and if you want to try out the example commands you should have a Hypothesis dev install . The easiest way to run all of the tests in the hypothesis/h repo (including both Python and JavaScript tests) is by running the make test command …
This is the index page for a series of posts about our approach to Python unit tests at Hypothesis : Running the Hypothesis Python Tests Debugging Failing Tests with pytest Writing Simple Python Unit Tests Arrange, Act, Assert Python Test Factories with factory_boy Testing that an Exception is Raised with pytest …
How to make code reviews a more pleasant and empowering experience for everyone involved.
How to set up a Pyblosxom blog on Ubuntu using the Gunicorn WSGI server and Nginx web server.
How to encrypt the contents of a git repo with git-crypt.
The design of the broken link checker API for CKAN .
Check your CKAN site for broken links and produce a report.