Skip to content

Commit

Permalink
Create conftest.py to fix seed and mock urandom before all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
donRumata03 committed Mar 30, 2024
1 parent c2a1591 commit 33770db
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import random
import subprocess
import sys
from unittest.mock import patch

import pytest

from golem.utilities.utils import set_random_seed


@pytest.fixture(autouse=True)
def stabilize_random():
set_random_seed(42)

def urandom_mock(n):
return random.randbytes(n)

# os.random is the source of random used in the uuid library
# normally, it's „true“ random, but to stabilize tests,
# it uses seeded `random` library
with patch('os.urandom', urandom_mock):
yield

0 comments on commit 33770db

Please sign in to comment.