Skip to content

autorun: clear builtins._ so a False result does not fail later tests - #5221

Open
DresslerFrank wants to merge 3 commits into
secdev:masterfrom
DresslerFrank:remove-dead-session-save
Open

DresslerFrank wants to merge 3 commits into
secdev:masterfrom
DresslerFrank:remove-dead-session-save

Conversation

@DresslerFrank

Copy link
Copy Markdown
Contributor

Tests that followed one ending in False were reported as failed. UTScapy uses the last expression value as the result, and a successful assert does not replace it. autorun_commands did not delete builtins._ at the start of a test, so the previous False stayed in place.

The following uts file demonstrates the problem:

% False result carries over

+ Carry over

= one
False

= two
assert True

two raises nothing and does not set a new value, but it was reported as failed.

The purpose of the scapy_session code was unclear. The history showed that it belonged to session save/load, removed in 13621d1 ("Sessions removed"), and that this code had been left behind. Searching the rest of the tree for those leftovers by hand looked like more work than it was worth, and a good fit for AI, so I asked it to find and remove them as well.

Fixes #5220

AI-Assisted: yes (Grok 4.7)

Tests that followed one ending in False were reported as failed. UTScapy
uses the last expression value as the result, and a successful assert
does not replace it. autorun_commands did not delete builtins._ at the
start of a test, so the previous False stayed in place.

The following uts file demonstrates the problem:

    % False result carries over

    + Carry over

    = one
    False

    = two
    assert True

`two` raises nothing and does not set a new value, but it was reported
as failed.

The purpose of the scapy_session code was unclear. The history showed
that it belonged to session save/load, removed in 13621d1 ("Sessions
removed"), and that this code had been left behind. Searching the rest
of the tree for those leftovers by hand looked like more work than it
was worth, and a good fit for AI, so I asked it to find and remove
them as well.

Fixes secdev#5220

AI-Assisted: yes (Grok 4.7)

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread scapy/autorun.py
interp = ScapyAutorunInterpreter(locals=my_globals)
try:
del builtins.__dict__["scapy_session"]["_"]
del builtins.__dict__["_"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the important change that fixes UTScapy.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.85%. Comparing base (6173a18) to head (a1ec589).

Files with missing lines Patch % Lines
scapy/main.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5221   +/-   ##
=======================================
  Coverage   80.84%   80.85%           
=======================================
  Files         393      393           
  Lines       98414    98398   -16     
=======================================
- Hits        79564    79555    -9     
+ Misses      18850    18843    -7     
Files with missing lines Coverage Δ
scapy/autorun.py 84.91% <100.00%> (-0.25%) ⬇️
scapy/config.py 84.38% <ø> (-0.03%) ⬇️
scapy/main.py 70.09% <0.00%> (+1.25%) ⬆️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UTS incorrectly shows some tests as failing following an unsccessful test

1 participant