diff --git a/tests/conftest.py b/tests/conftest.py index 0a27d5cf..6e87b554 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,7 +20,9 @@ MINI_BATCH_SIZE = 8 RANDOM_SEED = 42 -set_seed(42) +@pytest.fixture(scope='function', autouse=True) +def reset_prngs(): + set_seed(42) @pytest.fixture(scope="session", autouse=True) @@ -236,7 +238,7 @@ def load_mnist_model_softmax(): return model -@pytest.fixture(scope="session", autouse=True) +@pytest.fixture(scope="session", autouse=False) def load_hf_distilbert_sequence_classifier(): """ TODO @@ -248,8 +250,8 @@ def load_hf_distilbert_sequence_classifier(): return model -@pytest.fixture(scope="session", autouse=True) -def mock_hf_text(): +@pytest.fixture(scope="session", autouse=False) +def dummy_hf_tokenizer(): """ TODO """ @@ -262,4 +264,4 @@ def mock_hf_text(): @pytest.fixture(scope="session", autouse=True) def set_env(): """Set ENV var, so test outputs are not polluted by progress bars and warnings.""" - os.environ["PYTEST"] = "1" + os.environ["PYTEST"] = "1" \ No newline at end of file diff --git a/tests/functions/test_pytorch_model.py b/tests/functions/test_pytorch_model.py index 09631a14..f995fb8c 100644 --- a/tests/functions/test_pytorch_model.py +++ b/tests/functions/test_pytorch_model.py @@ -250,17 +250,17 @@ def test_add_mean_shift_to_first_layer(load_mnist_model): [ ( lazy_fixture("load_hf_distilbert_sequence_classifier"), - lazy_fixture("mock_hf_text"), + lazy_fixture("dummy_hf_tokenizer"), False, {}, - nullcontext(np.array([[0.01157812, 0.03933399]])), + nullcontext(np.array([[0.00424026, -0.03878461]])), ), ( lazy_fixture("load_hf_distilbert_sequence_classifier"), - lazy_fixture("mock_hf_text"), + lazy_fixture("dummy_hf_tokenizer"), False, {"labels": torch.tensor([1]), "output_hidden_states": True}, - nullcontext(np.array([[0.01157812, 0.03933399]])), + nullcontext(np.array([[0.00424026, -0.03878461]])), ), ( lazy_fixture("load_hf_distilbert_sequence_classifier"), @@ -268,14 +268,14 @@ def test_add_mean_shift_to_first_layer(load_mnist_model): 102]]), 'attention_mask': torch.tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])}, False, {"labels": torch.tensor([1]), "output_hidden_states": True}, - nullcontext(np.array([[0.01157812, 0.03933399]])), + nullcontext(np.array([[0.00424026, -0.03878461]])), ), ( lazy_fixture("load_hf_distilbert_sequence_classifier"), - lazy_fixture("mock_hf_text"), + lazy_fixture("dummy_hf_tokenizer"), True, {}, - nullcontext(np.array([[0.49306148, 0.5069385]])), + nullcontext(np.array([[0.51075452, 0.4892454]])), ), ( lazy_fixture("load_hf_distilbert_sequence_classifier"),