Files
pytorch/test/test_logging.py
hippocookie 01fb9676b8 Enable UFMT format on test/license.py test/logging.py (#125737)
Fixes some files in #123062

Run lintrunner on files:
test/license.py test/logging.py

```bash
$ lintrunner -a --take UFMT --all-files
ok No lint issues.
Successfully applied all patches.
```
Co-authored-by: Nikita Shulga <2453524+malfet@users.noreply.github.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/125737
Approved by: https://github.com/ezyang, https://github.com/malfet
2024-05-11 01:52:35 +00:00

25 lines
821 B
Python

# Owner(s): ["module: unknown"]
import torch
from torch.testing._internal.common_utils import run_tests, TestCase
class LoggingTest(TestCase):
def testApiUsage(self):
"""
This test verifies that api usage logging is not triggered via static
initialization. Since it's triggered at first invocation only - we just
subprocess
"""
s = TestCase.runWithPytorchAPIUsageStderr("import torch")
self.assertRegex(s, "PYTORCH_API_USAGE.*import")
# import the shared library directly - it triggers static init but doesn't call anything
s = TestCase.runWithPytorchAPIUsageStderr(
f"from ctypes import CDLL; CDLL('{torch._C.__file__}')"
)
self.assertNotRegex(s, "PYTORCH_API_USAGE")
if __name__ == "__main__":
run_tests()