Skip to content

[TESTS] Add global random seed for deterministic test#525

Open
Stephen0512 wants to merge 4 commits intoRedHatQE:masterfrom
Stephen0512:master
Open

[TESTS] Add global random seed for deterministic test#525
Stephen0512 wants to merge 4 commits intoRedHatQE:masterfrom
Stephen0512:master

Conversation

@Stephen0512
Copy link
Copy Markdown

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

  • More reproducible and reliable tests
  • Easier debugging of failures
  • Consistent CI behavior

The issue was identified during an ongoing research project.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 seed from Python’s random module.
  • Seeds the global RNG (seed(17)) at module import time.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_hawkular.py Outdated
from wrapanapi.systems import HawkularSystem
from wrapanapi.systems.hawkular import CanonicalPath, Resource, ResourceData, ResourceType

seed(17)
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This suggestion seems reasonable. @Stephen0512, mind looking into it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hello @ogajduse, thanks for taking a look at this PR. I have changed the code to make the randomness local.

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.

3 participants