forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue python#22002: Make full use of test discovery in test sub-packa…
…ges. Adds `load_package_tests` function to test.support, uses it in test_asyncio, test_email, test_json, test_tools, test_importlib and all test_importlib sub-packages to implement test discovery.
- Loading branch information
Showing
21 changed files
with
104 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,10 @@ | ||
import os | ||
import sys | ||
import unittest | ||
from test.support import run_unittest, import_module | ||
from test.support import load_package_tests, import_module | ||
|
||
# Skip tests if we don't have threading. | ||
import_module('threading') | ||
# Skip tests if we don't have concurrent.futures. | ||
import_module('concurrent.futures') | ||
|
||
|
||
def suite(): | ||
tests = unittest.TestSuite() | ||
loader = unittest.TestLoader() | ||
for fn in os.listdir(os.path.dirname(__file__)): | ||
if fn.startswith("test") and fn.endswith(".py"): | ||
mod_name = 'test.test_asyncio.' + fn[:-3] | ||
try: | ||
__import__(mod_name) | ||
except unittest.SkipTest: | ||
pass | ||
else: | ||
mod = sys.modules[mod_name] | ||
tests.addTests(loader.loadTestsFromModule(mod)) | ||
return tests | ||
|
||
|
||
def test_main(): | ||
run_unittest(suite()) | ||
def load_tests(*args): | ||
return load_package_tests(os.path.dirname(__file__), *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from . import test_main | ||
from . import load_tests | ||
import unittest | ||
|
||
|
||
if __name__ == '__main__': | ||
test_main() | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from test.test_email import test_main | ||
from test.test_email import load_tests | ||
import unittest | ||
|
||
test_main() | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,5 @@ | ||
import os | ||
import sys | ||
from test import support | ||
import unittest | ||
from test.support import load_package_tests | ||
|
||
def test_suite(package=__package__, directory=os.path.dirname(__file__)): | ||
suite = unittest.TestSuite() | ||
for name in os.listdir(directory): | ||
if name.startswith(('.', '__')): | ||
continue | ||
path = os.path.join(directory, name) | ||
if (os.path.isfile(path) and name.startswith('test_') and | ||
name.endswith('.py')): | ||
submodule_name = os.path.splitext(name)[0] | ||
module_name = "{0}.{1}".format(package, submodule_name) | ||
__import__(module_name, level=0) | ||
module_tests = unittest.findTestCases(sys.modules[module_name]) | ||
suite.addTest(module_tests) | ||
elif os.path.isdir(path): | ||
package_name = "{0}.{1}".format(package, name) | ||
__import__(package_name, level=0) | ||
package_tests = getattr(sys.modules[package_name], 'test_suite')() | ||
suite.addTest(package_tests) | ||
else: | ||
continue | ||
return suite | ||
|
||
|
||
def test_main(): | ||
start_dir = os.path.dirname(__file__) | ||
top_dir = os.path.dirname(os.path.dirname(start_dir)) | ||
test_loader = unittest.TestLoader() | ||
support.run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir)) | ||
def load_tests(*args): | ||
return load_package_tests(os.path.dirname(__file__), *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
"""Run importlib's test suite. | ||
from . import load_tests | ||
import unittest | ||
|
||
Specifying the ``--builtin`` flag will run tests, where applicable, with | ||
builtins.__import__ instead of importlib.__import__. | ||
""" | ||
if __name__ == '__main__': | ||
from . import test_main | ||
test_main() | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
from .. import test_suite | ||
import os | ||
from test.support import load_package_tests | ||
|
||
|
||
def test_suite(): | ||
directory = os.path.dirname(__file__) | ||
return test_suite('importlib.test.builtin', directory) | ||
|
||
|
||
if __name__ == '__main__': | ||
from test.support import run_unittest | ||
run_unittest(test_suite()) | ||
def load_tests(*args): | ||
return load_package_tests(os.path.dirname(__file__), *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import load_tests | ||
import unittest | ||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
from .. import test_suite | ||
import os.path | ||
import unittest | ||
import os | ||
from test.support import load_package_tests | ||
|
||
|
||
def test_suite(): | ||
directory = os.path.dirname(__file__) | ||
return test_suite('importlib.test.extension', directory) | ||
|
||
|
||
if __name__ == '__main__': | ||
from test.support import run_unittest | ||
run_unittest(test_suite()) | ||
def load_tests(*args): | ||
return load_package_tests(os.path.dirname(__file__), *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import load_tests | ||
import unittest | ||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
from .. import test_suite | ||
import os.path | ||
import unittest | ||
import os | ||
from test.support import load_package_tests | ||
|
||
|
||
def test_suite(): | ||
directory = os.path.dirname(__file__) | ||
return test_suite('importlib.test.frozen', directory) | ||
|
||
|
||
if __name__ == '__main__': | ||
from test.support import run_unittest | ||
run_unittest(test_suite()) | ||
def load_tests(*args): | ||
return load_package_tests(os.path.dirname(__file__), *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import load_tests | ||
import unittest | ||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
from .. import test_suite | ||
import os.path | ||
import unittest | ||
import os | ||
from test.support import load_package_tests | ||
|
||
|
||
def test_suite(): | ||
directory = os.path.dirname(__file__) | ||
return test_suite('importlib.test.import_', directory) | ||
|
||
|
||
if __name__ == '__main__': | ||
from test.support import run_unittest | ||
run_unittest(test_suite()) | ||
def load_tests(*args): | ||
return load_package_tests(os.path.dirname(__file__), *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import load_tests | ||
import unittest | ||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
from .. import test_suite | ||
import os.path | ||
import unittest | ||
import os | ||
from test.support import load_package_tests | ||
|
||
|
||
def test_suite(): | ||
directory = os.path.dirname(__file__) | ||
return test.test_suite('importlib.test.source', directory) | ||
|
||
|
||
if __name__ == '__main__': | ||
from test.support import run_unittest | ||
run_unittest(test_suite()) | ||
def load_tests(*args): | ||
return load_package_tests(os.path.dirname(__file__), *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import load_tests | ||
import unittest | ||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters