Add __main__ guards to fx tests (#154715)

This PR is part of a series attempting to re-submit #134592 as smaller PRs.

In fx tests:

- Add and use a common raise_on_run_directly method for when a user runs a test file directly which should not be run this way. Print the file which the user should have run.
- Raise a RuntimeError on tests which have been disabled (not run)
- Remove any remaining uses of "unittest.main()""

Pull Request resolved: https://github.com/pytorch/pytorch/pull/154715
Approved by: https://github.com/Skylion007
This commit is contained in:
Anthony Barbier
2025-06-04 14:38:45 +00:00
committed by PyTorch MergeBot
parent cf9cad31df
commit c8d44a2296
20 changed files with 102 additions and 36 deletions

View File

@ -902,6 +902,11 @@ def prof_callable(callable, *args, **kwargs):
return callable(*args, **kwargs)
def raise_on_run_directly(file_to_call):
raise RuntimeError("This test file is not meant to be run directly, "
f"use:\n\n\tpython {file_to_call} TESTNAME\n\n"
"instead.")
def prof_func_call(*args, **kwargs):
return prof_callable(func_call, *args, **kwargs)