Now that my work includes coding in Python, the first thing that I paid attention to was all the Python tools that allowed me to replicate my dev setup in Ruby. Here’s what I have so far.
Testing to me these days is a lot like seatbelts while riding a car. I do not feel safe without them. So mastering a testing framework is always top priority for me when diving into a new language. I tried nose but it appears to have lost favor from one of the open-source communities I’m in.
Some things to note in the above code are the following:
Some examples for using this test framework combo are as follows.
There are a few things going on in that screenshot so let’s break it down to the meaty parts:
Continuous testing is a very important part of a development workflow and is, I would say, at the same level of importance as continuous integration. So I was very pleased to find that this is also easily implemented in Python as it is in Ruby. For Python, I came across sniffer which supported nose out of the box but was configurable enough to run testr and friends too. So now, when I edit a file in my project, sniffer detects the change and runs testr automatically:
Here’s another screenshot where I deliberately fail the test:
Here’s another screenshot showing how sniffer also automatically ran flake8 after my tests and detected a trailing whitespace:
Right now, I’ve only configured sniffer to indiscriminately run all test instead of selectively running tests depending on which file changed. This is easily configured though by overriding a sniffer class and adding some logic there.
I found coverage which does the job just as well as Ruby’s SimpleCov:
Here’s the HTML report showing which lines ran and which were skipped
As with Ruby’s SimpleCov, green lines were executed while red lines were not.
I’ve gotten so used to continuous testing on my local environment that coding without it feels like driving without seatbelts. It’s really good to know that Python is just as feature rich in this regard as Ruby.