Using the Python mock library to fake regular functions during tests

While writing unit tests in Python, there will often be times where you’ll need to fake the result of a function as testing against the actual function may be impossible. A simple example is a random function since one can’t predict what it will return. Another could be a database call for a database that’s only available in certain environments. Python’s mock library is the de facto standard when mocking functions in Python, yet I have always struggled to understand it from the official documentation. [Read More]

Headless Browser Testing with Chrome and Firefox

When utilising Selenium to test web applications, I was always under the impression that PhantomJS was the only option for servers without an X server. I have nothing but good things to say about PhantomJS and have used it successfully for testing in the past. However, while working on some pull requests for splinter recently, I discovered that Chrome and Firefox can also be configured to do the same thing. [Read More]

Essential Python Libraries

So in case you haven’t noticed … I’m a little (VERY) in love with Python as a programming language. I use it for everything now, from web development, to scripting and everything in between. As such, I thought I’d put together an article of the many amazing libraries that I think every Python programmer needs to know about. Now there’s no doubt in my mind that there are heaps that I’ve missed, but we have to start somewhere. [Read More]

Serving a Python Flask Website on Hostmonster

Hey there folks, it’s been a while! In this post, I’ll be guiding you through setting up Hostmonster (or similar shared hosting providers) to serve a Python Flask web application. I’ll be using my new Flaskage template project as the application, but naturally you can adapt this solution to work with any Flask application. We’ll create a temporary build directory to put things in: 1 2 mkdir ~/build cd ~/build First, start by building and installing Python on the system: [Read More]

Curing RSI (Repetitive Strain Injury)

Being a computer user all my life was bound to catch up with me, and it did several years ago. One day, I started having constant pain in my wrists, hands and fingers. Having never experienced something like this before, I assumed it would go away, so I continued working as per usual for the next week. Unfortunately the pain did not go away and I was forced to cut down on typing and using my PC. [Read More]