Pytest With Eric

Learn to write production level Python Unit Tests with Pytest

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 »

As software engineers, handling errors is an important part of code development.

How often do users behave unexpectedly? More often than not. In most respect, people, systems and the Universe are random.

Maybe your code expects user input or takes data from a received packet and transforms it, perhaps performing complex calculations.

Network delays, even reordering or corrupted data. Whatever be it, it’s good to plan for the worst.

Read more »

Javascript Object Notation (JSON) is arguably one of the most popular data exchange formats over the web.

Web services use serialisation to convert data from low-level data structures to JSON format that allows receiving services to easily deserialise it.

When writing Unit tests the need for testing JSON input and outputs is one of high importance.

Test data, API Responses and sometimes even config files are defined in JSON which makes it necessary to understand how to read and write to it, using Pytest.

Read more »

When writing unit tests, it’s hard to consider all possible edge cases and validate that your code works correctly.

This is sometimes caught in production and a quick and speedy patch needs to be deployed. Only for a new bug to emerge later.

There will always be cases you didn’t consider, making this an ongoing maintenance job. Unit testing solves only some of these issues.

Read more »

There are several frameworks for building robust and scalable Rest APIs with Python.

FastAPI, Flask and Django are the most popular, reliable and easy to use.

However, building APIs is incomplete without thorough testing.

Unit tests and Integration tests are necessary to ensure your API works for client use cases.

Most of these frameworks come with inbuilt Unittest integration, but writing and maintaining test classes can be cumbersome.

Read more »

Do you find yourself with lots of boilerplate code when writing unit tests?

Monotonous code like database setup, teardown, API clients or test data can be painful to replicate across 10s or 100s of unit tests.

When writing tests, it’s often necessary to set up some initial state before running the actual test code.

This setup can be time-consuming to write, especially when there are multiple tests that require the same steps.

Read more »

Continuous Integration (CI) is an essential practice in software development. It ensures you release small and quick.

Unit and Integration Testing form a vital piece of this CI/CD Pipeline. After all, what good is untested code?

But, does the thought of setting up and maintaining a CI/CD server like Jenkins, Ansible or Code Commit cause you stress?

Read more »

Testing is an essential part of software development and delivery.

Writing code without testing it is like delivering a half-baked cake.

We explored various types of production software testing in our article on types of software testing.

However, writing tests can be a tedious and time-consuming task, and you often find yourself repeating the same code over and over again.

Read more »

Originally developed in the 1940s, APIs have exploded in popularity during the last 30–40 years.

Back in the day, SOAP APIs were popular with Rest and GraphQL becoming the new norm.

As a means to share data between applications and databases, APIs form the building blocks of your software application.

A software application requires the ability to read and write data from a database.

To achieve this, it’s necessary that both the code and the database speak the same language. This is achieved through database drivers.

How useful is software that cannot talk to other software? Or where you cannot decouple the backend from the front end?

Read more »

Testing is an important part of the software development lifecycle (SDLC).

It helps ensure that your application is reliable, stable, and less prone to bugs (nobody is 100% immune).

Pytest is a popular testing framework to help you write and run tests for Python.

Testing helps identify bugs and errors in the software before its released to end users.

This helps prevent costly and damaging consequences.

Read more »
0%