Skip to content

Commit 5f5beee

Browse files
authored
Set a fixed random seed during testing (#1056)
Some of the tests became more flaky with the move to NumPy 2. In all cases, random numbers were involved at some point. Setting a fixed random seed made the tests reproducible and (so far) seems to have stopped the flakiness.
1 parent 54125c8 commit 5f5beee

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/openfermion/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,20 @@
99
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
12+
1213
import os
14+
import random
15+
import pytest
16+
import numpy as np
1317

1418

1519
def pytest_configure(config):
1620
# fail tests when using deprecated cirq functionality
1721
os.environ['CIRQ_TESTING'] = "true"
22+
23+
24+
@pytest.fixture(autouse=True)
25+
def set_random_seed():
26+
"""Set a fixed random seed when testing."""
27+
random.seed(0)
28+
np.random.seed(0)

0 commit comments

Comments
 (0)