Python is one of today’s most popular languages, with good reason. We’ve talked about Python development before and mentioned automation as being one of its more attractive factors. Today, we’ll take a look at the best Python tools for test automation and see which ones you should be using depending on your needs and development approach.
PyUnit—or UnitTest—is part of the standard Python library and comes with several advantages. You won’t have to install any additional modules to run it. It’s working principle is similar to other xUnit frameworks so you won’t need a strong Python background to use it if you’re already familiar with xUnit. It’s also very easy to run individual test cases, making it very flexible and fast, generating test reports in less than a second.
These come with cons: since the framework is inspired from junit, it uses the camelCase convention rather than Python’s snake_case, which can be very confusing. It’s also very abstract and requires a lot of boilerplate code. Still, for simple tests, you can’t go wrong with it.
2. Python Robot Framework
Robot Framework is a very popular for acceptance testing, acceptance test driven development, and robotic process automation. It can also be implemented with Java (Jython) and .Net (IronPython). This lets users create high-level keywords from existing ones using the same syntax they use in test cases. If you’re using Robot as a Pythoon framework, it’s also compatible across Windows, MacOS, and Linux.
To run it, you need Python 2.7.14 or above, as well as pip, Python’s package manager. You’ll also need to download a development framework such as PyCharm or any other IDE. But don’t worry—it’s all free.
Its advantages are many: its keyword-driven-test approach makes tests more readable. It’s highly-extensible. It can run parallel tests via a Selenium Grid, It’s test data syntax is easy to use. Unfortunately, parallel testing is not built in, and it can be tricky to create customized HTML reports using Robot.
Still, for beginners to test automation and development, Robot is easier to use than either PyTest or PyUnit due to its rich built-in libraries. For more complex automation, however, you might need to resort to PyTest.
Possibly the most widely-used test framework, PyTest is another great option. It’s easy to use, well-documented, and open-source, and comes with many useful features that have had giants like Dropbox changing from PyUnit to PyTest.
You don’t need anything complex to work with PyTest: just a command line, Python’s package manager, and a development IDE.
As a result of how PyTest works, it allows for more compact test suites than you’d have with PyUnit. Unlike with other tools, you won’t need to use a debugger or check logs to see if a test has failed. PyTest lets you store all values inside test cases and will inform you which values asserted, and which ones failed. You won’t need much boilerplate code. It provides you with special routines that make tests easier to write and understand, you can use fixtures to cover parameter combinations without rewriting your test cases, there are many available plugins.
Sadly, this all comes with a main drawback: you’ll need to compromise compatibility, as tests written in PyTest won’t run on other frameworks. You’ll also need to fully understand Python, but bottom line is: it’s better than UnitTest in terms of handling complex test cases, but for simpler ones (and if you’re not willing to learn Python), you may be better off with Robot.
4. Python Behave
If you follow behavior-driven development, you’ll want a behavior-driven testing framework. This is where Behave comes in.
All you need is basic Python knowledge, Python 2.7.14 or above, a package manager, and your preferred IDE.
Because it uses semi-formal language and a domain vocabulary, Behave keeps behavior consistent throughout your organization. Teams working on different modules with similar features are coordinated. Details feature reasoning and thinking, giving you better product specs that can be understood by both QAs and developers, as well as your stakeholders and managers. Its big drawback is that black box testing is the only kind it works for.
If black box testing is all you want to do, Behave is great. But for integration and unit testing, you’re better off with PyTest.
5. Python Gauge
Made by the same people who developed Selenium, Gauge is an open-source framework that lets you integrate continuous testing into CI/CD pipeline. Guage been gaining a lot of momentum due to its cross-browser testing functionality.
Many plug-ins are supported, as well as all major languages and command lines. Cross-browser tests can be automated, and imposes scalability of products across your Developer, Business, and QA teams.
The biggest drawback to Gauge is that it’s relatively young, and as with all technologies, needs a bit of time to evolve. Still, you should keep an eye on it if you need cross-browser testing and see how it matures.
6. Python Lettuce
Still on the behavior-driven automation tools, Lettuce is another great one. Like with other frameworks, you’ll need Python 2.7.14 or above, as well as an IDE and a Python package manager.
Because its main goal is to focus on the common behavior-driven development tasks, it lets you create more than one scenario to describe features using natural language. This makes Dev and QA specs of similar format, so it is easier to coordinate the two teams. And, unlike Behave, it does more than black-box testing.
The one big con against Lettuce comes from one of its strengths: dev, business, and QA teams need to communicate for the implementation to succeed. Without it, the Lettuce process becomes ambiguous, leading to problems down the line.
7. Python Jasmine
Jasmine has no external dependencies and supports asynchronous and DOM-less test cases. its syntax is simple and easy to read AND comes with parallel execution of server and client-side test cases. The community is active, so if you need support, you’re bound to find it. It does, however, stress the value of applications business over technical details. It’s an older tool, which can be both good and bad depending on how you look at it.
8. Python Splinter
Splinter is another tool used to write automated tests for web applications, and it works as an abstraction layer on top of a browser automation tool such as Selenium. With it, you can automate browser actions, like visiting a page and interacting with it.
The fact that it’s a high-level API makes it very easy to write headless browser tests for your applications. Unfortunately, that’s basically all it does.
9. Python Locust
You won’t need UIs or bloated XML to use it, either—just plain, old Python code. It could do with better documentation in some cases, but overall, it’s a great tool for load tests.
10. Python RedwoodHQ
Another great framework for load testing is RedwoodHQ. It supports complete automation and management of software testing. In addition to supporting Python, you can also use C# and Java, and it comes with an in-built IDE, so no need to install another. It works by creating a website interface that lets multiple people work together and run their tests from one web location.
It’s very user-friendly, supports parallel testing, makes it very easy to create and modify tests, is compatible with continuous integration tools, and is suitable for both front-end and back-end testing. Overall, a good alternative to Selenium testing if you’re looking for something different.