[TESTS] Add global random seed for deterministic test#525
[TESTS] Add global random seed for deterministic test#525Stephen0512 wants to merge 4 commits intoRedHatQE:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make tests/test_hawkular.py deterministic by fixing the randomness source so that sampling-based test setup is reproducible across runs.
Changes:
- Imports
seedfrom Python’srandommodule. - Seeds the global RNG (
seed(17)) at module import time.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from wrapanapi.systems import HawkularSystem | ||
| from wrapanapi.systems.hawkular import CanonicalPath, Resource, ResourceData, ResourceType | ||
|
|
||
| seed(17) |
There was a problem hiding this comment.
Calling seed(17) at module import time mutates Python’s global RNG state for the entire pytest process, which can create cross-test coupling and order-dependent behavior (this module may be imported mid-run, resetting the RNG sequence for other tests). Prefer using a local RNG (e.g., random.Random(17).sample(...)) or save/restore random.getstate() / random.setstate() around the specific sampling so the determinism is limited to this test logic. If the intent is to seed the whole suite, do it once in a session-scoped autouse fixture (e.g., in tests/conftest.py) rather than in a single test module import.
There was a problem hiding this comment.
This suggestion seems reasonable. @Stephen0512, mind looking into it?
There was a problem hiding this comment.
Hello @ogajduse, thanks for taking a look at this PR. I have changed the code to make the randomness local.
Description
This PR sets a fixed global random seed after imports in the test file to ensure deterministic and reproducible test behavior.
Motivation
Some tests rely on randomness without a fixed seed, which can lead to flaky tests, inconsistent CI results, and difficulty reproducing failures.
Change
A global random seed is initialized to make random behavior consistent across test runs.
Benefits
The issue was identified during an ongoing research project.