Skip to content

test: add random seed in conftest #1958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

allrob23
Copy link

@allrob23 allrob23 commented Apr 17, 2025

This PR adds a fixed random.seed(42) to pytest_configure in conftest.py to ensure deterministic behavior for tests that rely on Python’s random module.

This change was motivated by the test_registry, which includes logic that uses random. Without setting a seed, test outcomes could vary between runs, making it harder to debug or reproduce issues. By setting the seed once at the start of the test session, we improve consistency and test reliability.

@manics
Copy link
Member

manics commented Apr 17, 2025

Can you say a bit more about which tests were failing, and how this contributed to the problems?
We use random resource names and ports in several JupyterHub repos to reduce the risk of conflicts.

@allrob23
Copy link
Author

hello @manics, I noticed test_registry uses port = randint(10000, 65535) in tests methods to pick random ports, which is great for avoiding conflicts. Since there iss a small chance of ports overlapping between runs, I thought adding a seed in pytest_configure could help make test runs more consistent and easier to debug if we ever need to reproduce results.

This change keeps the randomization benefits for resource names and ports but ensures the same sequence every time, which is a common practice to make tests predictable and maintainable. I’m hoping this supports the team work on JupyterHub by adding a bit more reliability to our testing setup. Happy to discuss other ideas or tweak this approach!

@minrk
Copy link
Member

minrk commented Apr 17, 2025

@allrob23
Copy link
Author

Hey @minrk,

Thanks for pointing this out, and I totally understand your concern.

These PRs are part of a research project we're conducting, and while we can't share all the details just yet, I want to clarify that each change is reviewed carefully before submission. We're not aiming to create noise or burden maintainers — on the contrary, we hope to contribute positively and learn from the process.

Due to the nature of the research, we're required to use an anonymous account for now. However, once the article is published, we'll be able to identify ourselves and share more context around the project and its contributions.

That said, we really appreciate feedback like this, and we'll take extra care moving forward to ensure our contributions are clearly beneficial and well-motivated.

Thanks again

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