regrtest.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #! /usr/bin/env python3
  2. """
  3. Script to run Python regression tests.
  4. Run this script with -h or --help for documentation.
  5. """
  6. import os
  7. import sys
  8. from test.libregrtest import main
  9. # Alias for backward compatibility (just in case)
  10. main_in_temp_cwd = main
  11. def _main():
  12. global __file__
  13. # Remove regrtest.py's own directory from the module search path. Despite
  14. # the elimination of implicit relative imports, this is still needed to
  15. # ensure that submodules of the test package do not inappropriately appear
  16. # as top-level modules even when people (or buildbots!) invoke regrtest.py
  17. # directly instead of using the -m switch
  18. mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
  19. i = len(sys.path) - 1
  20. while i >= 0:
  21. if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
  22. del sys.path[i]
  23. else:
  24. i -= 1
  25. # findtestdir() gets the dirname out of __file__, so we have to make it
  26. # absolute before changing the working directory.
  27. # For example __file__ may be relative when running trace or profile.
  28. # See issue #9323.
  29. __file__ = os.path.abspath(__file__)
  30. # sanity check
  31. assert __file__ == os.path.abspath(sys.argv[0])
  32. main()
  33. if __name__ == '__main__':
  34. _main()