forked from robotframework/SeleniumLibrary
-
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.
Clean up run_unit_tests.py. (robotframework#662)
Finding unit tests is rewritten by using test discovery functionality provided by the unittest module in Python 2.7 and newer. This means unit tests cannot be executed with Python 2.6 anymore, but we've decided to drop its support anyway (robotframework#620). Tests won't be run with Python 2.6 on Travis anymore either. Also removed utils related to loading modules from S2L.utils. This unit test related code didn't belong under the main project in the first place.
- Loading branch information
1 parent
8272486
commit f5ba504
Showing
3 changed files
with
16 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
language: python | ||
sudo: false | ||
python: | ||
- "2.6" | ||
- "2.7" | ||
install: | ||
#- pip install pep8 --use-mirrors | ||
|
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,22 @@ | ||
import env | ||
import os, sys | ||
import unittest | ||
from Selenium2Library import utils | ||
#!/usr/bin/env python | ||
|
||
def run_unit_tests(modules_to_run=[]): | ||
(test_module_names, test_modules) = utils.import_modules_under( | ||
env.UNIT_TEST_DIR, include_root_package_name = False, pattern="test*.py") | ||
from os.path import abspath, dirname, join | ||
from unittest import defaultTestLoader, TextTestRunner | ||
import sys | ||
|
||
bad_modules_to_run = [module_to_run for module_to_run in modules_to_run | ||
if module_to_run not in test_module_names] | ||
if bad_modules_to_run: | ||
print("Specified test module%s not exist: %s" % ( | ||
' does' if len(bad_modules_to_run) == 1 else 's do', | ||
', '.join(bad_modules_to_run))) | ||
return -1 | ||
|
||
tests = [unittest.defaultTestLoader.loadTestsFromModule(test_module) | ||
for test_module in test_modules] | ||
CURDIR = dirname(abspath(__file__)) | ||
|
||
runner = unittest.TextTestRunner() | ||
result = runner.run(unittest.TestSuite(tests)) | ||
rc = len(result.failures) + len(result.errors) | ||
if rc > 255: rc = 255 | ||
return rc | ||
|
||
if __name__ == '__main__': | ||
sys.exit(run_unit_tests(sys.argv[1:])) | ||
def run_unit_tests(): | ||
sys.path.insert(0, join(CURDIR, '..', 'src')) | ||
try: | ||
suite = defaultTestLoader.discover(join(CURDIR, 'unit'), 'test_*.py') | ||
result = TextTestRunner().run(suite) | ||
finally: | ||
sys.path.pop(0) | ||
return min(len(result.failures) + len(result.errors), 255) | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(run_unit_tests()) |