Skip to content
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

Isolated mode fails with non-deterministic parameterization #239

Open
virtuald opened this issue Feb 20, 2025 · 2 comments
Open

Isolated mode fails with non-deterministic parameterization #239

virtuald opened this issue Feb 20, 2025 · 2 comments

Comments

@virtuald
Copy link
Member

There's probably a clever way to support this, but I'm not sure it's worth the time. Here's something that fails:

def get_alliance_stations() -> list[str]:
    stations = (1, 2, 3)
    if "CI" in os.environ:  # pragma: no branch
        return [
            f"{alliance}{station}"
            for alliance in ("Blue", "Red")
            for station in stations
        ]
    else:  # pragma: no cover
        return [f"Blue{random.choice(stations)}", f"Red{random.choice(stations)}"]

@pytest.mark.parametrize("station", get_alliance_stations())
def test_fuzz(control: TestController, station: str) -> None:
    ...
@virtuald
Copy link
Member Author

An ugly workaround that a user can do for this situation is the following:

def get_alliance_stations() -> list[str]:
    import json
    cached = os.environ.get("ALLIANCE_CACHE", None)
    if cached:
        return json.loads(cached)

    stations = (1, 2, 3)
    if "CI" in os.environ:  # pragma: no branch
        choices = [
            f"{alliance}{station}"
            for alliance in ("Blue", "Red")
            for station in stations
        ]
    else:  # pragma: no cover
        choices = [f"Blue{random.choice(stations)}", f"Red{random.choice(stations)}"]

    os.environ["ALLIANCE_CACHE"] = json.dumps(choices)
    return choices

@auscompgeek
Copy link
Member

pytest-xdist doesn't support this either, so if they don't have a solution I also don't think it's worth us spending the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

2 participants