[Python-Dev] [Python-checkins] r86945 - python/branches/py3k/Lib/test/__main__.py

Brett Cannon brett at python.org
Fri Dec 3 20:22:18 CET 2010


I just want to say thanks for doing this, Michael. __main__.py is IMO
woefully underused and it's great to see Python dogfooding the feature
along with making it easier to explain how to run our unit tests.

On Thu, Dec 2, 2010 at 17:34, michael.foord <python-checkins at python.org> wrote:
> Author: michael.foord
> Date: Fri Dec  3 02:34:01 2010
> New Revision: 86945
>
> Log:
> Initial implementation of Lib/test/__main__.py so we can run tests with 'python -m test'
>
> Added:
>   python/branches/py3k/Lib/test/__main__.py   (contents, props changed)
>
> Added: python/branches/py3k/Lib/test/__main__.py
> ==============================================================================
> --- (empty file)
> +++ python/branches/py3k/Lib/test/__main__.py   Fri Dec  3 02:34:01 2010
> @@ -0,0 +1,38 @@
> +import os
> +import sys
> +import sysconfig
> +
> +from test import support
> +from test.regrtest import main
> +
> +# findtestdir() gets the dirname out of __file__, so we have to make it
> +# absolute before changing the working directory.
> +# For example __file__ may be relative when running trace or profile.
> +# See issue #9323.
> +__file__ = os.path.abspath(__file__)
> +
> +# sanity check
> +assert __file__ == os.path.abspath(sys.argv[0])
> +
> +# When tests are run from the Python build directory, it is best practice
> +# to keep the test files in a subfolder.  It eases the cleanup of leftover
> +# files using command "make distclean".
> +if sysconfig.is_python_build():
> +    TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build')
> +    TEMPDIR = os.path.abspath(TEMPDIR)
> +    if not os.path.exists(TEMPDIR):
> +        os.mkdir(TEMPDIR)
> +
> +# Define a writable temp dir that will be used as cwd while running
> +# the tests. The name of the dir includes the pid to allow parallel
> +# testing (see the -j option).
> +TESTCWD = 'test_python_{}'.format(os.getpid())
> +
> +TESTCWD = os.path.join(TEMPDIR, TESTCWD)
> +
> +# Run the tests in a context manager that temporary changes the CWD to a
> +# temporary and writable directory. If it's not possible to create or
> +# change the CWD, the original CWD will be used. The original CWD is
> +# available from support.SAVEDCWD.
> +with support.temp_cwd(TESTCWD, quiet=True):
> +    main()
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>


More information about the Python-Dev mailing list