提交 e052f593 编写于 作者: R Rudá Moura

Merge pull request #344 from lmr/improve-test-detection-heuristics

avocado: Add another branch in test detection heuristics
...@@ -18,6 +18,7 @@ Test loader module. ...@@ -18,6 +18,7 @@ Test loader module.
""" """
import os import os
import re
import sys import sys
import imp import imp
import inspect import inspect
...@@ -99,18 +100,35 @@ class TestLoader(object): ...@@ -99,18 +100,35 @@ class TestLoader(object):
test_class = test.NotATest test_class = test.NotATest
test_parameters = test_parameters_queue test_parameters = test_parameters_queue
except ImportError, details: # Since a lot of things can happen here, the broad exception is
# justified. The user will get it unadulterated anyway, and avocado
# will not crash.
except Exception, details:
if os.access(test_path, os.X_OK): if os.access(test_path, os.X_OK):
# Module can't be imported, and it's executable. Let's try to # Module can't be imported, and it's executable. Let's try to
# execute it. # execute it.
test_class = test.SimpleTest test_class = test.SimpleTest
test_parameters = test_parameters_simple test_parameters = test_parameters_simple
else: else:
# Module can't be imported and it's not an executable. Our # Module can't be imported and it's not an executable. Let's
# best guess is that this is a buggy test. # see if there's an avocado import into the test. Although
# not entirely reliable, we hope it'll be good enough.
likely_avocado_test = False
with open(test_path, 'r') as test_file_obj:
test_contents = test_file_obj.read()
# Actual tests will have imports starting on column 0
patterns = ['^from avocado.* import', '^import avocado.*']
for pattern in patterns:
if re.search(pattern, test_contents, re.MULTILINE):
likely_avocado_test = True
break
if likely_avocado_test:
test_class = test.BuggyTest test_class = test.BuggyTest
params['exception'] = details params['exception'] = details
else:
test_class = test.NotATest
test_parameters = test_parameters_queue test_parameters = test_parameters_queue
sys.path.pop(sys.path.index(test_module_dir)) sys.path.pop(sys.path.index(test_module_dir))
return test_class, test_parameters return test_class, test_parameters
......
docs/source/diagram.png

66.3 KB | W: | H:

docs/source/diagram.png

76.1 KB | W: | H:

docs/source/diagram.png
docs/source/diagram.png
docs/source/diagram.png
docs/source/diagram.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册