3 """Test the copy of nose in this directory, by running that nose against itself.
5 You can test nose using nose in other ways, but if you don't use this script,
6 you might have one installation of nose testing another installation, which is
12 # In the absence of some sort of deep renaming magic, nose can't reasonably
13 # test a different installation of itself, given the existence of the global
14 # module registry sys.modules .
16 # If installed system-wide with setuptools, setuptools (via the site-packages
17 # easy-install.pth) takes you at your word and ensures that the installed nose
18 # comes first on sys.path . So the only way to test a copy of nose other than
19 # the installed one is to install that version (e.g. by running python setup.py
22 # This script provides a way of running nose on nose's own tests without
23 # installing the version to be tested, nor uninstalling the currently-installed
31 if __name__ == "__main__":
32 this_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
35 if sys.version_info >= (3,):
36 # Under Python 3.x, we need to 'build' the source (using 2to3, etc)
37 # first. 'python3 setup.py build_tests' will put everything under
38 # build/tests (including nose itself, since some tests are inside the
40 # The 'py3where' argument in setup.cfg will take care of making sure we
41 # pull our tests only from the build/tests directory. We just need to
42 # make sure the right things are on sys.path.
43 lib_dirs = glob.glob(os.path.join(this_dir, 'build', 'lib*'))
44 test_dir = os.path.join(this_dir, 'build', 'tests')
45 if not os.path.isdir(test_dir):
46 raise AssertionError("Error: %s does not exist. Use the setup.py 'build_tests' command to create it." % (test_dir,))
49 env = pkg_resources.Environment(search_path=lib_dirs)
50 distributions = env["nose"]
51 assert len(distributions) == 1, (
52 "Incorrect usage of selftest.py; please see DEVELOPERS.txt")
53 dist = distributions[0]
57 # Always make sure our chosen test dir is first on the path
58 sys.path.insert(0, test_dir)