s
March 23, 2024, 7:44 p.m. |

Simon Willison's Weblog simonwillison.net

time-machine example test for a segfault in Python


Here's a really neat testing trick by Adam Johnson. Someone reported a segfault bug in his time-machine library. How you you write a unit test that exercises a segfault without crashing the entire test suite?


Adam's solution is a test that does this:


subprocess.run([sys.executable, "-c", code_that_crashes_python], check=True)


sys.executable is the path to the current Python executable - ensuring the code will run in the same virtual environment as the test suite itself. …

adam example library machine python solution test testing trick

Data Architect

@ University of Texas at Austin | Austin, TX

Data ETL Engineer

@ University of Texas at Austin | Austin, TX

Lead GNSS Data Scientist

@ Lurra Systems | Melbourne

Senior Machine Learning Engineer (MLOps)

@ Promaton | Remote, Europe

Director, Clinical Data Science

@ Aura | Remote USA

Research Scientist, AI (PhD)

@ Meta | Menlo Park, CA | New York City