File size: 948 Bytes
0ba9d09 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | """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)
|