"""Shared setup for the test suite. Several lecture files print five decimal places of an arithmetic result, too close for float32 to separate, so those files raise the default precision when they are imported. A test may import a file that does not, so the suite raises the precision here for every test alike. We run this at module scope, not in a fixture, because pytest imports a conftest before it imports or collects anything else. A module-scoped fixture in a test file would otherwise build its values first, in the lower precision. """ import pytest import torch torch.set_default_dtype(torch.float64) # Match what every script does in main(). torch.set_num_threads(1) # One thread is the fastest here, because these networks are small. @pytest.fixture(scope="session", autouse=True) def _restore_defaults(): """Put the process back the way it was once the session ends.""" yield torch.set_default_dtype(torch.float32)