Pytest With Eric

Learn to write production level Python Unit Tests with Pytest

There’s no doubt that Pytest fixtures are incredibly useful and help you write clean and maintainable tests.

But what if you want to do something more dynamic?

Maybe set up a database connection or pass different data inputs to each test case?

Setting up and tearing down identical fixtures with very minor changes leads to code repetition and maintenance nightmare.

Maybe you want to parameterize your fixtures?

Read more »

As a Python developer striving for accurate and efficient testing, you will likely encounter scenarios where verifying floating-point values or approximate comparisons presents challenges.

In many real-world applications, especially with scientific computing, simulations, high-performance computing, financial calculations, and data analysis, you’ll often deal with floating-point numbers.

These numbers are represented in computers using a finite number of binary digits, which can lead to rounding errors and precision limitations.

So what do you and how do you test these floating-point values?

Read more »

You’ve written code and Unit tests, and want to make sure it works. You simply run the pytest command in your terminal to run them the tests. Boom! some tests fail.

How do you debug it?

To debug, it’s sometimes helpful to run one test, run tests in a specific module or class, or run tests based on a marker.

But how do you run just a single test?

Read more »

In our fast-paced world, every millisecond matters and user experience is paramount.

The importance of faster code faster cannot be overstated.

Beyond correct functioning, it’s imperative to ensure that it operates efficiently and consistently across varying workloads.

This is where performance testing and benchmarking step in to uncover bottlenecks, inefficiencies, and regressions.

Read more »

Writing repeat code is likely one of the things you least enjoy. At least it’s the case for me.

In a world striving for time, cost and resource efficiency less is more.

How can we apply this same philosophy to Unit Testing?

We often need to reuse resources (like input data, database connections, shared objects and so on) across our Unit Tests.

Read more »

As a Python developer, you’re likely familiar with Pytest, the popular Unit Testing framework.

It’s a powerful tool to test your Python programs using easy and concise syntax, with a plethora of built-in functionality and Pytest plugins to enhance your testing experience.

Most developers use the CLI to run tests. But it’s actually possible (and easier) to run tests with just a single mouse click. You might be wondering, “Really? But how?”.

If you’re using VS Code then you can set it up in just a few minutes. Saving you countless hours in iterative development and testing time.

Read more »

Software testing is critical to your development process, ensuring your code works as expected.

As Python continues to gain popularity as a backend and scripting language, choosing the right testing framework becomes increasingly important.

Two prominent options in the Python ecosystem are Unittest and Pytest. Both frameworks provide powerful capabilities for writing and executing tests but differ in approach, features, and community support.

In this article, we delve into the comparison between Unittest vs Pytest, shedding light on their strengths, weaknesses, and distinctive features.

Read more »

While developing any software solution, keeping track of events is crucial. Logging serves as a means of tracking events to catch software bugs, as they happen.

Although Pytest is great at running tests, it doesn’t automatically display the output of print statements or logs, which can be a problem when trying to debug failing tests.

Read more »