mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Automatically skip thirdparty test if not importable
This commit is contained in:
@@ -56,7 +56,7 @@ def pytest_generate_tests(metafunc):
|
|||||||
cases = list(run.collect_dir_tests(base_dir, test_files))
|
cases = list(run.collect_dir_tests(base_dir, test_files))
|
||||||
if thirdparty:
|
if thirdparty:
|
||||||
cases.extend(run.collect_dir_tests(
|
cases.extend(run.collect_dir_tests(
|
||||||
os.path.join(base_dir, 'thirdparty'), test_files))
|
os.path.join(base_dir, 'thirdparty'), test_files, True))
|
||||||
metafunc.parametrize('case', cases)
|
metafunc.parametrize('case', cases)
|
||||||
if 'refactor_case' in metafunc.fixturenames:
|
if 'refactor_case' in metafunc.fixturenames:
|
||||||
base_dir = metafunc.config.option.refactor_case_dir
|
base_dir = metafunc.config.option.refactor_case_dir
|
||||||
|
|||||||
16
test/run.py
16
test/run.py
@@ -120,6 +120,7 @@ class IntegrationTestCase(object):
|
|||||||
self.start = start
|
self.start = start
|
||||||
self.line = line
|
self.line = line
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.skip = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
name = os.path.basename(self.path) if self.path else None
|
name = os.path.basename(self.path) if self.path else None
|
||||||
@@ -171,7 +172,7 @@ def collect_file_tests(lines, lines_to_execute):
|
|||||||
correct = None
|
correct = None
|
||||||
|
|
||||||
|
|
||||||
def collect_dir_tests(base_dir, test_files):
|
def collect_dir_tests(base_dir, test_files, check_thirdparty=False):
|
||||||
for f_name in os.listdir(base_dir):
|
for f_name in os.listdir(base_dir):
|
||||||
files_to_execute = [a for a in test_files.items() if a[0] in f_name]
|
files_to_execute = [a for a in test_files.items() if a[0] in f_name]
|
||||||
lines_to_execute = reduce(lambda x, y: x + y[1], files_to_execute, [])
|
lines_to_execute = reduce(lambda x, y: x + y[1], files_to_execute, [])
|
||||||
@@ -180,10 +181,23 @@ def collect_dir_tests(base_dir, test_files):
|
|||||||
# only has these features partially.
|
# only has these features partially.
|
||||||
if is_py25 and f_name in ['generators.py', 'types.py']:
|
if is_py25 and f_name in ['generators.py', 'types.py']:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
skip = None
|
||||||
|
if check_thirdparty:
|
||||||
|
lib = f_name.replace('_.py', '')
|
||||||
|
try:
|
||||||
|
# there is always an underline at the end.
|
||||||
|
# It looks like: completion/thirdparty/pylab_.py
|
||||||
|
__import__(lib)
|
||||||
|
except ImportError:
|
||||||
|
skip = 'Thirdparty-Library %s not found.' % lib
|
||||||
|
|
||||||
path = os.path.join(base_dir, f_name)
|
path = os.path.join(base_dir, f_name)
|
||||||
source = open(path).read()
|
source = open(path).read()
|
||||||
for case in collect_file_tests(StringIO(source),
|
for case in collect_file_tests(StringIO(source),
|
||||||
lines_to_execute):
|
lines_to_execute):
|
||||||
case.path = path
|
case.path = path
|
||||||
case.source = source
|
case.source = source
|
||||||
|
if skip:
|
||||||
|
case.skip = skip
|
||||||
yield case
|
yield case
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from . import base
|
from . import base
|
||||||
from .run import \
|
from .run import \
|
||||||
TEST_COMPLETIONS, TEST_DEFINITIONS, TEST_ASSIGNMENTS, TEST_USAGES
|
TEST_COMPLETIONS, TEST_DEFINITIONS, TEST_ASSIGNMENTS, TEST_USAGES
|
||||||
@@ -97,6 +99,8 @@ def run_related_name_test(case):
|
|||||||
|
|
||||||
|
|
||||||
def test_integration(case, monkeypatch, pytestconfig):
|
def test_integration(case, monkeypatch, pytestconfig):
|
||||||
|
if case.skip is not None:
|
||||||
|
pytest.skip(case.skip)
|
||||||
repo_root = base.root_dir
|
repo_root = base.root_dir
|
||||||
monkeypatch.chdir(os.path.join(repo_root, 'jedi'))
|
monkeypatch.chdir(os.path.join(repo_root, 'jedi'))
|
||||||
testers = {
|
testers = {
|
||||||
|
|||||||
Reference in New Issue
Block a user