Skip to main content

5 posts tagged with "pytest"

pytest tag description

View All Tags

Pytest mock pitfalls

8 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Writing tests that are effective and maintainable is an art. While mocking is a powerful tool, it's not a silver bullet and can be misused. This final article of the mocking series will cover the best practices and common pitfalls of mocking in Python, ensuring your tests are robust, readable, and provide a high degree of confidence in your code.

Pytest: Mocking Objects and Classes

9 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Mocking entire classes and objects is a crucial skill for unit testing complex code. When a function instantiates a class or calls methods on a passed-in object, you need a way to control that object's behavior without executing its real logic. This article will cover advanced mocking techniques, focusing on how to mock classes and instance methods using both the standard unittest.mock library and the more convenient pytest-mock plugin. We will also clarify key distinctions between different types of test doubles.

How to Make Doctests Easy in Python with Gitpod and VS Code

6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

If you're writing doctests in Python using Gitpod or VS Code, you don鈥檛 need much to get started. Python鈥檚 built-in doctest module lets you write examples in your function鈥檚 docstring using the familiar >>> prompt, and then run those examples as tests. This is great for small, focused functions or when you want your documentation to double as lightweight tests.