adding a "test" fork to a setup.py package
I'm packaging up the SSL support for Python 2.3, and I'd like to be able to include the unit test for it along with the package. Ideally, I'd like to be able to say % python setup.py build % python setup.py test and have the regrtest.py module run my tests. Any ideas (examples) of how to do that? Bill
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sep 11, 2007, at 2:12 PM, Bill Janssen wrote:
I'm packaging up the SSL support for Python 2.3, and I'd like to be able to include the unit test for it along with the package. Ideally, I'd like to be able to say
% python setup.py build % python setup.py test
and have the regrtest.py module run my tests. Any ideas (examples) of how to do that?
The email package does something like this by having most of the tests in a subpackage of enum, with a shim in Lib/test for regrtest. The standalone package has a testall script, but that should really be converted to nosetests or some such. - -Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iQCVAwUBRubgtXEjvBPtnXfVAQIGJgP/aeCOlybJj0sA3k6WOWMCOhugggLHHtO2 lu5v7hZZG5nqe5iApwxjbiylxvMRfRB6HS7dgEABx1D5OC3uFssn3kUzokfBtsxy I/e4qYiTSCG3WZacqytAqmjKt3FkceIo+l6YKx29FjPlaoHHz0UzCJIdW9AuJp4a Ussk9AOPIXo= =FMDE -----END PGP SIGNATURE-----
Barry Warsaw schrieb:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Sep 11, 2007, at 2:12 PM, Bill Janssen wrote:
I'm packaging up the SSL support for Python 2.3, and I'd like to be able to include the unit test for it along with the package. Ideally, I'd like to be able to say
% python setup.py build % python setup.py test
and have the regrtest.py module run my tests. Any ideas (examples) of how to do that?
The email package does something like this by having most of the tests in a subpackage of enum, with a shim in Lib/test for regrtest. The standalone package has a testall script, but that should really be converted to nosetests or some such.
ctypes does it in a similar way. Tests are in the Lib/ctypes/test package. Thomas
It's actually not bad. I put the test code and the data files in a "test" subdirectory of my distribution, then added the following to the setup.py file: class Test (Command): user_options = [] def initialize_options(self): pass def finalize_options(self): pass def run (self): """Run the regrtest module appropriately""" # figure out where the _ssl2 extension will be put b = build(self.distribution) b.initialize_options() b.finalize_options() extdir = os.path.abspath(b.build_platlib) # now set up the load path topdir = os.path.dirname(os.path.abspath(__file__)) localtestdir = os.path.join(topdir, "test") sys.path.insert(0, topdir) # for ssl package sys.path.insert(0, localtestdir) # for test module sys.path.insert(0, extdir) # for _ssl2 extension # make sure the network is enabled import test.test_support test.test_support.use_resources = ["network"] # and load the test and run it os.chdir(localtestdir) the_module = __import__("test_ssl", globals(), locals(), []) # Most tests run to completion simply as a side-effect of # being imported. For the benefit of tests that can't run # that way (like test_threaded_import), explicitly invoke # their test_main() function (if it exists). indirect_test = getattr(the_module, "test_main", None) if indirect_test is not None: indirect_test() and added cmdclass={'test': Test}, to the setup call. Irritating that you have to manually install the test files as data_files. Also irritating that data_files aren't automatically added to the manifest, and that Test has to have null initialize_options and finalize_options. And that there's no easy way to figure out where the build process left the extension. Bill
participants (3)
-
Barry Warsaw -
Bill Janssen -
Thomas Heller