Slash Development Time with pytest
At Six Feet Up, we do a lot of Plone development and customization. Plone, an enterprise-grade open source CMS, comes with various types of tests out-of-the-box. In the past 10 years, we have used doc tests and Plone test cases, as well as standard unit tests from the Python framework and from the Python standard library.
These test frameworks come with a lot of boilerplate, and a lot of setup and tear-down. While some of it may be necessary, boilerplate can be sometimes be involved and stands in the way of getting the tests written.
On the other hand, pytest is a simpler unit testing framework for Python with many built-in fixtures, such as fixtures for dealing with temporary test files or caching commonly used values, that facilitates writing tests. pytest can turn some of the boilerplate into quick and easy-to-use decorators that can be put onto different tests. And, when necessary, tests can easily be marked for skipping on certain platforms or in certain conditions.
Pytests can shorten the total time it takes to write tests. It also makes it easy to parameterize tests and build a giant set of test suites based on a list of dictionaries that pass in expected inputs and outputs.
PyCharm and pytest on Windows
PyCharm is an Integrated Development Environment (IDE) used in computer programming, specifically for the Python language. As a developer running on a Mac, I recently had to work in a Windows environment, which prompted me to download and install PyCharm so I could have a useful editor in Windows. Fortunately, PyCharm is cross-platform, and PyCharm is really well integrated with pytest. It has a nice debugger built in, which makes it easy to track down hard to find bugs.
Using pytest in PyCharm is usually pretty straightforward: click on a specific test module and run that set of tests. In PyCharm, it's possible to even go down into the test module and run a single test. Additionally, PyCharm can automatically watch for file save changes and run tests continuously. It keeps looping through, running the tests so the developer can keep modifying his/her code until all tests pass without necessarily committing any code.
Prevent Regressions with pytest
Getting a set of fast running tests can dramatically speed up the development process and ensures developers don't break various areas of the project. With pytest, developers can immediately see if there's a test failure in an unexpected area in the project that is causing regressions. Typically, these issues cannot be found without running tests. Using pytest reduces the amount of time spent on manual QA because those regressions would have been caught before they ever got to the testing or production environments.
There are many ways to automate and make tests more robust. Contact me if you want to use pytest to build up your tests.