Skip to content

fix: define behavior class within the test function in test_1511_set_attribute.py to make it thread-local#3826

Merged
ikrommyd merged 2 commits intoscikit-hep:mainfrom
ikrommyd:fix-behavior-test
Feb 3, 2026
Merged

fix: define behavior class within the test function in test_1511_set_attribute.py to make it thread-local#3826
ikrommyd merged 2 commits intoscikit-hep:mainfrom
ikrommyd:fix-behavior-test

Conversation

@ikrommyd
Copy link
Copy Markdown
Collaborator

@ikrommyd ikrommyd commented Jan 26, 2026

I have hit this failure in CI once

 ==================================== ERRORS ====================================
___________________ ERROR at call of test_bad_behavior_array ___________________

    def test_bad_behavior_array():
        record = ak.contents.RecordArray([ak.contents.NumpyArray(np.arange(10))], ["x"])
        array = ak.Array(record, with_name="bad", behavior=behavior)
        assert isinstance(array, BadBehaviorArray)
    
>       assert array.fields == BadBehaviorArray.FIELD_STRING
E       AssertionError: assert 'I am not a list of fields!' == 'yo ho ho and a bottle of rum'
E         
E         - yo ho ho and a bottle of rum
E         + I am not a list of fields!

array      = <[FieldNotFoundError("no field 'I' in record with 1 fields") raised in repr()] BadBehaviorArray object at 0x2a2804d1a50>
record     = <RecordArray is_tuple='false' len='10'>
    <content index='0' field='x'>
        <NumpyArray dtype='int64' len='10'>[0 1 2 3 4 5 6 7 8 9]</NumpyArray>
    </content>
</RecordArray>

tests/test_1511_set_attribute.py:68: AssertionError

but can't reproduce locally with while (pytest tests/test_1511_set_attribute.py --parallel-threads 4); do; done.

The problem here is that this class is defined globally and therefore shared among threads and it has a setter for an attribute. Let's guard against multiple threads changing the attribute in parallel.

@ikrommyd ikrommyd changed the title test: define behavior class within the test to make it thread-local fix: define behavior class within the test function it test_1511_set_attribute.py to make it thread-local Jan 26, 2026
@ikrommyd ikrommyd changed the title fix: define behavior class within the test function it test_1511_set_attribute.py to make it thread-local fix: define behavior class within the test function in test_1511_set_attribute.py to make it thread-local Jan 26, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.65%. Comparing base (53744b2) to head (136de7c).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

see 2 files with indirect coverage changes

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

@github-actions
Copy link
Copy Markdown

The documentation preview is ready to be viewed at http://preview.awkward-array.org.s3-website.us-east-1.amazonaws.com/PR3826

Copy link
Copy Markdown
Member

@ariostas ariostas left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@ikrommyd
Copy link
Copy Markdown
Collaborator Author

ikrommyd commented Feb 3, 2026

Hit it again in #3823. It's strange that I can't get it locally 🤣. Anyways, this is how we should properly test this so I'll merge.

@ikrommyd ikrommyd merged commit 5f5f0ab into scikit-hep:main Feb 3, 2026
40 checks passed
@ikrommyd ikrommyd deleted the fix-behavior-test branch February 3, 2026 17:51
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