Skip to content

save one failure snapshot per test, not one per run - #15061

Merged
Nir-Az merged 3 commits into
realsenseai:developmentfrom
AviaAv:iq-per-test-snapshot
May 18, 2026
Merged

Nir-Az merged 3 commits into
realsenseai:developmentfrom
AviaAv:iq-per-test-snapshot

Conversation

@AviaAv

@AviaAv AviaAv commented May 17, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@AviaAv
AviaAv requested a review from Nir-Az May 17, 2026 07:23

@Nir-Az Nir-Az left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Auto-generated review by rs-agentic bot

Overall this is a clean and well-motivated fix — changing from a single boolean flag to a per-test-name set is the right approach to allow each test to save its own failure snapshot. A few observations below.



_snapshot_saved = False
_snapshot_saved = set()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[rs-agentic bot] ⚠️ Thread Safety: _snapshot_saved is a module-level set mutated without any lock. The check-then-add pattern (if name in _snapshot_saved … _snapshot_saved.add(name)) is not atomic. If tests ever run concurrently (e.g. via pytest-xdist or any future parallel runner), two threads could both pass the guard and both save a snapshot.

If concurrent execution is possible, consider protecting the guard with a threading.Lock:

import threading
_snapshot_lock = threading.Lock()
_snapshot_saved = set()

# inside the function:
with _snapshot_lock:
    if name in _snapshot_saved:
        return
    _snapshot_saved.add(name)

If the test framework is strictly single-threaded this is fine as-is, but worth a comment.

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.

concurrent execution not possible

"""
global _snapshot_saved
if _snapshot_saved:
name = os.path.basename( test_file ).replace( '.py', '' )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[rs-agentic bot] 💡 Enhancement — use os.path.splitext for robustness: .replace('.py', '') does a string replace, which would incorrectly strip .py if it appeared anywhere else in the filename (e.g. pytest-helper.py.bak). The idiomatic alternative is:

name = os.path.splitext(os.path.basename(test_file))[0]

This only removes the final extension and is the standard pattern in the stdlib.

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.

won't change, just a line moved

cv2.imwrite( filename, image )
log.i( f"Saved failure snapshot: {filename}" )
_snapshot_saved = True
_snapshot_saved.add( name )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[rs-agentic bot] 🔍 Module-level state persists across the entire process lifetime: Because _snapshot_saved is a module-level set, it is shared and never reset for the lifetime of the Python process. This means:

  • If a test is re-run within the same session (e.g. pytest --count, rerun-failures plugin, or interactive debugging), the second run will not save a snapshot even if it fails — the name is already in the set.

If repeated-run support matters, consider clearing the set in a pytest fixture (e.g. session-scoped autouse) or documenting this intentional "first failure only" semantic in the docstring.

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.

Known limitation, not a bug

@AviaAv
AviaAv requested a review from Nir-Az May 18, 2026 07:19
@Nir-Az Nir-Az closed this May 18, 2026
@Nir-Az Nir-Az reopened this May 18, 2026
@Nir-Az
Nir-Az merged commit 1986698 into realsenseai:development May 18, 2026
57 of 58 checks passed
@AviaAv
AviaAv deleted the iq-per-test-snapshot branch May 18, 2026 14:29
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.

2 participants