diff options
author | Alex Stewart <alex@foogod.com> | 2010-09-01 14:24:47 -0700 |
---|---|---|
committer | Alex Stewart <alex@foogod.com> | 2010-09-01 14:24:47 -0700 |
commit | c58f8d55e1aac4b1eec792e85cdd3b376ec4c4e2 (patch) | |
tree | c8225ab52b5d038edf359547868521733735ecb2 | |
parent | b98f0b1e46bfa4a2f11012d1c2d28caf59163864 (diff) | |
download | nose-c58f8d55e1aac4b1eec792e85cdd3b376ec4c4e2.tar.gz |
Added a 'py3where' option to nosetests
-rw-r--r-- | nose/config.py | 16 | ||||
-rw-r--r-- | selftest.py | 15 | ||||
-rw-r--r-- | setup.cfg | 1 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | setup3lib.py | 6 |
5 files changed, 29 insertions, 11 deletions
diff --git a/nose/config.py b/nose/config.py index fa5ff60..4a88ac5 100644 --- a/nose/config.py +++ b/nose/config.py @@ -168,6 +168,7 @@ class Config(object): self.testNames = () self.verbosity = int(env.get('NOSE_VERBOSE', 1)) self.where = () + self.py3where = () self.workingDir = None """ @@ -202,6 +203,7 @@ class Config(object): self.testNames = [] self.verbosity = int(env.get('NOSE_VERBOSE', 1)) self.where = () + self.py3where = () self.workingDir = os.getcwd() self.traverseNamespace = False self.firstPackageWins = False @@ -282,6 +284,10 @@ class Config(object): if options.testNames is not None: self.testNames.extend(tolist(options.testNames)) + if options.py3where is not None: + if sys.version_info >= (3,): + options.where = options.py3where + # `where` is an append action, so it can't have a default value # in the parser, or that default will always be in the list if not options.where: @@ -450,6 +456,16 @@ class Config(object): "to the list of tests to execute. [NOSE_WHERE]" ) parser.add_option( + "--py3where", action="append", dest="py3where", + metavar="PY3WHERE", + help="Look for tests in this directory under Python 3.x. " + "Functions the same as 'where', but only applies if running under " + "Python 3.x or above. Note that, if present under 3.x, this " + "option completely replaces any directories specified with " + "'where', so the 'where' option becomes ineffective. " + "[NOSE_PY3WHERE]" + ) + parser.add_option( "-m", "--match", "--testmatch", action="store", dest="testMatch", metavar="REGEX", help="Files, directories, function names, and class names " diff --git a/selftest.py b/selftest.py index 436e773..78809d3 100644 --- a/selftest.py +++ b/selftest.py @@ -30,15 +30,19 @@ import sys if __name__ == "__main__": this_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) lib_dir = this_dir + test_dir = this_dir if sys.version_info >= (3,): # Under Python 3.x, we need to 'build' the source (using 2to3, etc) # first. 'python3 setup.py build_tests' will put everything under # build/tests (including nose itself, since some tests are inside the - # nose source), so we'll run from that directory instead. + # nose source) + # The 'py3where' argument in setup.cfg will take care of making sure we + # pull our tests only from the build/tests directory. We just need to + # make sure the right things are on sys.path. lib_dir = os.path.join(this_dir, 'build', 'lib') - this_dir = os.path.join(this_dir, 'build', 'tests') - if not os.path.isdir(this_dir): - raise AssertionError("Error: %s does not exist. Use the setup.py 'build_tests' command to create it." % (this_dir,)) + test_dir = os.path.join(this_dir, 'build', 'tests') + if not os.path.isdir(test_dir): + raise AssertionError("Error: %s does not exist. Use the setup.py 'build_tests' command to create it." % (test_dir,)) try: import pkg_resources env = pkg_resources.Environment(search_path=[lib_dir]) @@ -49,7 +53,6 @@ if __name__ == "__main__": except ImportError: pass # Always make sure our chosen test dir is first on the path - sys.path.insert(0, this_dir) - os.chdir(this_dir) + sys.path.insert(0, test_dir) import nose nose.run_exit() @@ -6,6 +6,7 @@ tag_svn_revision = 1 with-doctest=1 doctest-extension=.rst doctest-fixtures=_fixtures +py3where=build/tests [bdist_rpm] doc_files = README.txt @@ -24,7 +24,7 @@ try: test_suite = 'nose.collector', use_2to3 = True, test_dirs = test_dirs, - # The following is needed for the ispackage doctests to work right: + test_build_dir = 'build/tests', pyversion_patching = True, ) diff --git a/setup3lib.py b/setup3lib.py index 8c024bf..27bdb93 100644 --- a/setup3lib.py +++ b/setup3lib.py @@ -79,7 +79,7 @@ else: test_base = self.distribution.test_build_dir if not test_base: bcmd = self.get_finalized_command('build') - test_base = os.path.join(bcmd.build_base, 'tests') + test_base = bcmd.build_base self.test_base = test_base def run(self): @@ -91,6 +91,7 @@ else: modified = [] py_modified = [] doc_modified = [] + dir_util.mkpath(test_base) for testdir in test_dirs: for srcdir, dirnames, filenames in os.walk(testdir): destdir = os.path.join(test_base, srcdir) @@ -121,9 +122,6 @@ else: else: log.warn("Warning: pyversion_patching specified in setup config but patch module not found. Patching will not be performed.") - # Some test frameworks read things from setup.cfg and expect it to - # be present in the current directory. In any case, doesn't hurt.. - file_util.copy_file('setup.cfg', test_base, update=True) dir_util.mkpath(lib_base) self.reinitialize_command('egg_info', egg_base=lib_base) self.run_command('egg_info') |