Writing and Reporting Assertions in pytest 8.x
Utilizing Standard assert Statements
pytest enhances the standard Python assert statement, allowing you to use built-in Python constructs without boilerplate code while maintaining detailed introspection. For instance, to verify a function's return value:
# content of test_calculation.py
def calculate_product(x, y):
return x * y
def test_m ...
Posted on Sun, 14 Jun 2026 17:03:33 +0000 by talkster5
Automating Android Device Testing with MonkeyRunner
Overview
MonkeyRunner is a tool built using Jython (a Python implementation on the Java platform) that provides an API for controlling Android devices or emulators from outside of Android code. It allows writing Python scripts to install applications, run tests, send input events, and capture screenshots for debugging purposes.
The tool is prim ...
Posted on Tue, 09 Jun 2026 17:12:59 +0000 by bri4n
Spring Framework 5 Logging Configuration and Testing Integration
Spring Framework 5 standardized its logging infrastructure by removing support for Log4j 1.x configurations via LOG4jConfigListener. Applications should migrate to Log4j2 for consistent logging behavior across the framework.
Configure Log4j2 by adding the following dependencies to your project:
<dependency>
<groupId>org.apache.l ...
Posted on Sat, 23 May 2026 16:02:13 +0000 by Diego17
Generating HTML Reports and Code Coverage for Python Unit Tests
Test Execution and HTML Reporting
To generate visual test reports using the HTMLTestRunner or BSTestRunner libraries, you must configure a test runner that outputs to an HTML file. The following script demonstrates how to discover tests dynamically and produce a timestamped report.
import unittest
import datetime
from pathlib import Path
# As ...
Posted on Wed, 20 May 2026 03:39:33 +0000 by henka
Using DeepDiff for Object Comparison in Python
DeepDiff is a Python library designed to compare objects and identify differences between them. It supports various data types including dictionaries, iterables, strings, and more.
Installation
Install the library using pip:
pip install deepdiff==4.3.2
Comparing Text Files
To compare text files, read their contents and pass them to DeepDiff:
f ...
Posted on Sun, 17 May 2026 20:57:01 +0000 by buddysal
Web Automation Made Simple: A Comprehensive Guide to DrissionPage
The Problem with Traditional Approaches
When performing web scraping with requests, websites requiring authentication demand extensive analysis of network packets, JavaScript source code, and complex request construction. Anti-crawling mechanisms like CAPTCHAs, JavaScript obfuscation, and signature parameters create high barriers to entry. When ...
Posted on Sat, 16 May 2026 23:42:53 +0000 by borris_uk
Building and Testing the Bustub Database System
Repository Setup
Begin by creating a private repository on GitHub named bustub-private. Follow these steps to mirror the original public repository:
# Clone the original repository as bare
git clone --bare https://github.com/cmu-db/bustub.git bustub-original
# Mirror to your private repository
cd bustub-original
git push https://github.com/stu ...
Posted on Wed, 13 May 2026 06:20:18 +0000 by vino4all
Mocking Singleton Template Classes with Google Mock
This guide demonstrates techniques for mocking singleton template classes using Google Mock.
Method 1: Direct Mocking via Static Method
For a simple singleton template class, you can directly mock its methods using GMock's MOCK_METHOD macro. This approach assumes the singletno class already exposes methods intended for mocking.
#include <gte ...
Posted on Tue, 12 May 2026 22:21:15 +0000 by onlinegs
Using pytest-rerunfailures to Improve Test Stability with Automatic Retry Mechanisms
Automated test cases can fail intermittently due to transient issues such as service deployments, network instability, or temporary resource contention. Introducing a retry mechanism helps filter out flaky failures and improves overall test reliability.
The pytest-rerunfailures plugin integrates with pytest to automatically re-execute failed te ...
Posted on Thu, 07 May 2026 21:38:28 +0000 by bdemo2
Implementing Data-Driven Testing with Pytest's Parametrize Decorator
The @pytest.mark.parametrize decorator accepts a string of parameter names and a list of data sets to execute a test function multiple times with different inputs.
The first argument is a comma-separated string of parameter names. The second argument is a list, where each element is a tuple providing values for those parameters.
For a single pa ...
Posted on Thu, 07 May 2026 21:02:34 +0000 by bulrush