1# Owner(s): ["module: unknown"] 2 3import torch 4from torch.testing._internal.common_utils import run_tests, TestCase 5 6 7class LoggingTest(TestCase): 8 def testApiUsage(self): 9 """ 10 This test verifies that api usage logging is not triggered via static 11 initialization. Since it's triggered at first invocation only - we just 12 subprocess 13 """ 14 s = TestCase.runWithPytorchAPIUsageStderr("import torch") 15 self.assertRegex(s, "PYTORCH_API_USAGE.*import") 16 # import the shared library directly - it triggers static init but doesn't call anything 17 s = TestCase.runWithPytorchAPIUsageStderr( 18 f"from ctypes import CDLL; CDLL('{torch._C.__file__}')" 19 ) 20 self.assertNotRegex(s, "PYTORCH_API_USAGE") 21 22 23if __name__ == "__main__": 24 run_tests() 25