BugsInPy: a database of existing bugs in Python programs to enable controlled testing and debugging studies

Ratnadira Widyasari, Sheng Qin Sim, Camellia Lok, Haodi Qi, Jack Phan, Qijin Tay, Constance Tan, Fiona Wee, Jodie Ethelda Tan, Yuheng Yieh, Brian Goh, Ferdian Thung, Hong Jin Kang, Thong Hoang, David Lo, Eng Lieh OuhESEC/SIGSOFT FSE 2020 · DOI

Abstract

The 2019 edition of Stack Overflow developer survey highlights that, for the first time, Python outperformed Java in terms of popularity. The gap between Python and Java further widened in the 2020 edition of the survey. Unfortunately, despite the rapid increase in Python's popularity, there are not many testing and debugging tools that are designed for Python. This is in stark contrast with the abundance of testing and debugging tools for Java. Thus, there is a need to push research on tools that can help Python developers. One factor that contributed to the rapid growth of Java testing and debugging tools is the availability of benchmarks. A popular benchmark is the Defects4J benchmark; its initial version contained 357 real bugs from 5 real-world Java programs. Each bug comes with a test suite that can expose the bug. Defects4J has been used by hundreds of testing and debugging studies and has helped to push the frontier of research in these directions. In this project, inspired by Defects4J, we create another benchmark database and tool that contain 493 real bugs from 17 real-world Python programs. We hope our benchmark can help catalyze future work on testing and debugging tools that work on Python programs.

Introduction: The Python Tooling Gap

While Python has surged to become one of the most popular programming languages—driven by the explosion of data science and web development—the software engineering research community has largely focused on Java. This has led to a "tooling gap": there are many sophisticated automated debugging and repair tools for Java, but relatively few for Python.

A major bottleneck for research is the lack of high-quality benchmarks. To evaluate a new debugging tool, researchers need a collection of real bugs that are reproducible, isolated, and real-world. Before BugsInPy, researchers often had to spend hundreds of hours manually collecting their own data, leading to fragmented and non-reproducible studies.

The BugsInPy Infrastructure

The authors followed a rigorous manual curation process to build BugsInPy, inspired by the famous Defects4J benchmark for Java. Beyond a simple collection of commits, BugsInPy provides a robust infrastructure to facilitate research.

The multi-layered architecture of the BugsInPy framework.

As shown in the architectural diagram, the framework is organized into several layers designed to lower the barrier to entry for researchers:

  1. Bug Database: Stores bug metadata and the corresponding Git repositories.
  2. Database Abstraction: Handles the complexities of checking out specific buggy or fixed versions and managing environment dependencies.
  3. Test Execution Framework: Integrates essential tools like coverage.py for code coverage, MutPy for mutation testing, and PythonFuzz for fuzzing.
  4. Tool Layer: Provides a standardized interface for external testing and debugging tools to interact with the underlying data.

Dataset Composition and Scale

The primary contribution is the BugsInPy dataset, which at the time of publication was the largest curated database of real-world Python bugs available.

Summary of the 17 open-source Python projects included in BugsInPy.

The dataset includes 493 bugs from 17 diverse open-source projects, covering approximately 1.25 million lines of code. These projects span various domains, including machine learning (keras, spaCy), web frameworks (fastapi, sanic), and developer tools (ansible, black, httpie). This diversity ensures that tools evaluated on BugsInPy are tested against a wide range of coding styles and architectural patterns.

Methodology and Curation Challenges

Building such a dataset requires significant human effort—estimated at 831 man-hours. The process involved mining GitHub for commits that modified test files in projects with over 10,000 stars.

A major hurdle identified during curation was the "Tangled Commit": nearly 32% of potential bug fixes (235 out of 730) were discarded because they mixed a fix with unrelated refactoring or new features. To ensure the bugs were "isolated," two authors independently reviewed each commit, rejecting any that were not clean and focused solely on the bug fix.

Insights and Future Directions

Python’s unique characteristics, such as duck typing and dynamic collections, create bug patterns that differ significantly from statically typed languages like Java. Consequently, tools built for Java cannot simply be ported; they must be developed and validated on native Python bugs.

By providing a unified command-line interface and Docker-based environment, BugsInPy eliminates the "dependency hell" typically associated with large-scale project reproduction. Future work aims to expand the dataset and integrate more advanced automated program repair (APR) and fault localization tools, creating a comprehensive ecosystem for Python software engineering research.

Summary updated

BibTeX
@inproceedings{widyasari2020bugsinpy,
  author = {Ratnadira Widyasari and Sheng Qin Sim and Camellia Lok and Haodi Qi and Jack Phan and Qijin Tay and Constance Tan and Fiona Wee and Jodie Ethelda Tan and Yuheng Yieh and Brian Goh and Ferdian Thung and Hong Jin Kang and Thong Hoang and David Lo and Eng Lieh Ouh},
  title = {{BugsInPy: a database of existing bugs in Python programs to enable controlled testing and debugging studies}},
  booktitle = {ESEC/SIGSOFT FSE},
  year = {2020},
  doi = {10.1145/3368089.3417943},
}
Figure