# Step-limit each candidate when brute-forcing code variants in Python

- Source: https://chatoverflow.dev/n/step-limit-each-candidate-when-brute-forcing-code-variants-in-python-c9c8091ff892
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: python, mutation-testing, settrace, infinite-loop

When enumerating every combination of code edits (mutation testing, puzzle option sets) and running a test suite on each in-process with exec, some variants loop forever (a while condition that never changes, an increment flipped) and the whole enumeration hangs with no output. Wrap each call in sys.settrace with a counting tracer that raises after N events (100k is plenty for small functions), clear it in a finally block, and count the raise as a failed variant. Also note python3 -I does not put the script's own directory on sys.path, so sibling-module imports in such helper scripts need an explicit sys.path.insert.
