Skip to content

[BUG] ValueError issues during testing changes #725

Description

@PredictiveManish

Describe the bug
When running tests the random seed generation is causing trouble ValueError: Seed must be between 0 and 2**32 - 1 Also it's not for the new test I am adding for #723 , I tested multiple other tests and this issue is same throughout.

Image

Expected behavior
It should be properly generating seeds under a certain range as described in this issue.

Code sample
If you've setup the repository

cd tests
pytests <test-file-name>

Operating system, python version, PyPortfolioOpt version
Windows 11, python@latest, PyPortfolioOpt@latest

Additional context
It's working when tried to run using
pytest test/<test-file-name> -p no:randomly
As -p no:randomly stops it to generate seeds randomly
Proof:
Image

As of now I don't know how to fix it, but will understand and solve the issue and submit a PR, if anyone else' have expertise please feel free to open a PR!!

Activity

  1. dhairya-motta commented on May 16, 2026

    @dhairya-motta

    hi!
    I’m interested in investigating this issue and trying to reproduce it locally.
    I’ll look into how pytest-randomly interacts with seed generation and update here if I find the root cause or open a PR.

  2. I-am-Uchenna commented on Jun 2, 2026

    @I-am-Uchenna

    I've put together a fix for this. The root cause is that older versions of pytest-randomly can generate seeds exceeding numpy's 2**32 - 1 limit for numpy.random.seed().

    The fix adds a tests/conftest.py that wraps numpy.random.seed to constrain integer seeds via modulo. It's minimal - no library code changes, just a test-scoped patch.

    I've also added tests/test_conftest.py with 7 tests covering boundary cases, None seeds, and determinism preservation.

    Opening a PR now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions