Skip to content

Fix and improve test_random #135376

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
serhiy-storchaka opened this issue Jun 11, 2025 · 0 comments
Open

Fix and improve test_random #135376

serhiy-storchaka opened this issue Jun 11, 2025 · 0 comments
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes 3.15 new features, bugs and security fixes tests Tests in the Lib/test dir

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jun 11, 2025

#135326 exposed the fact that there was no tests for objects implementing __index__ in test_random, even if some code in the random module explicitly support them.

When trying to add more tests, I discovered that

  • Some code is literally duplicated for Random and SystemRandom tests. It is easy to make error by modifying only only one of the copy.
  • As consequence of this, some tests were only added for SystemRandom, even if they are not specific for SystemRandom.

There was also no tests for randint().

So the following PR reorganizes test_random: removes duplicated code, makes sure that implementation agnostic tests are run for both classes, and add few new tests.

Linked PRs

@serhiy-storchaka serhiy-storchaka added tests Tests in the Lib/test dir 3.13 bugs and security fixes 3.14 bugs and security fixes 3.15 new features, bugs and security fixes labels Jun 11, 2025
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jun 11, 2025
* Remove duplicated code. Tests for Random and SystemRandom now share
  the code.
* Move implementation agnostic tests that was only run for SystemRandom,
  so they are now run for Random too.
* Add tests for __index__() support.
* Add tests for randint().
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jun 11, 2025
* Remove duplicated code. Tests for Random and SystemRandom now share
  the code.
* Move implementation agnostic tests that was only run for SystemRandom,
  so they are now run for Random too.
* Add tests for __index__() support.
* Add tests for randint().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes 3.15 new features, bugs and security fixes tests Tests in the Lib/test dir
Projects
None yet
Development

No branches or pull requests

1 participant