Hybrid Fault-Driven Mutation Testing for Python
Saba Alimadadi, Golnaz Gharachorlu
TL;DR
This work addresses the gap in mutation testing for Python caused by dynamic typing by introducing PyTation, a hybrid static-dynamic mutation framework with seven Python-specific operators inspired by PySStuBs anti-patterns. PyTation identifies mutation candidates through a dual analysis, prunes unlikely mutants via execution coverage, and applies targeted AST mutations to simulate runtime faults, yielding many unique and complementary mutants relative to Cosmic Ray. Empirical evaluation on 13 real-world Python projects shows PyTation uncovers test gaps even in high-coverage code, with a high average mutation score and low equivalent-mutant rates, while offering distinct fault models. The approach advances practical mutation testing for Python, enabling deeper assessment of test suites and guiding test-suite augmentation with Python-centric fault scenarios.
Abstract
Mutation testing is an effective technique for assessing the effectiveness of test suites by systematically injecting artificial faults into programs. However, existing mutation testing techniques fall short in capturing many types of common faults in dynamically typed languages like Python. In this paper, we introduce a novel set of seven mutation operators that are inspired by prevalent anti-patterns in Python programs, designed to complement the existing general-purpose operators and broaden the spectrum of simulated faults. We propose a mutation testing technique that utilizes a hybrid of static and dynamic analyses to mutate Python programs based on these operators while minimizing equivalent mutants. We implement our approach in a tool called PyTation and evaluate it on 13 open-source Python applications. Our results show that PyTation generates mutants that complement those from general-purpose tools, exhibiting distinct behaviour under test execution and uncovering inadequacies in high-coverage test suites. We further demonstrate that PyTation produces a high proportion of unique mutants, a low cross-kill rate, and a low test overlap ratio relative to baseline tools, highlighting its novel fault model. PyTation also incurs few equivalent mutants, aided by dynamic analysis heuristics.
