我在下面运行鼻子测试命令,但它仅在第一个文件夹中运行测试,我在子目录中有其他测试。如何编辑命令以在我指定的文件夹的所有子目录中运行以下所有测试?
nosetests -s -v --ckan --with-pylons=test-core.ini ckan/tests/legacy/*
这是以下目录中测试的基本结构
https://github.com/ckan/ckan/tree/ckan-2.7.3/ckan/tests/legacy
答案 0 :(得分:1)
您可以编写脚本来生成所有必需的路径。
我使用以下内容:
#coding: utf-8
import os
import logging
log = logging.getLogger()
skip_list = []
def get_test_files(cur_path, test_files = []):
""" Find all files that started with test_ """
cur_dir_content = os.listdir(cur_path)
for i in cur_dir_content:
full_path = os.path.join(cur_path, i)
if os.path.islink(full_path):
continue
if os.path.isfile(full_path) and is_file_test(full_path):
test_files.append(full_path)
elif os.path.isdir(full_path):
get_test_files(full_path, test_files)
return test_files
def is_file_test(full_path):
""" Check if file is test"""
file_name, file_ext = os.path.splitext(os.path.basename(full_path))
if file_name[:5] == "test_" and file_ext == ".py":
if is_in_skip(full_path):
log.info("FILE: %s ... SKIP", full_path)
return False
return True
return False
def is_in_skip(full_path):
for i in skip_list:
if full_path.find(i) >= 0:
return True
return False
def execute_all_with_nosetests(path_list):
""" Test with nosetests.
"""
#compute paths
cur_dir = os.getcwd()
paths = map(lambda x: os.path.abspath(x), path_list)
relpath = "INSERT YOUR PATH"
paths = map(lambda x: os.path.relpath(x, relpath), paths)
paths = " ".join(paths)
os.chdir("INSERT TEST RUN FOLDER")
cmd = "nosetests -s -v --ckan --with-pylons=test-core.ini " + paths
os.system(cmd)
os.chdir(cur_dir)
if __name__ == "__main__":
test_list = get_test_files("INSERT_BASE_PATH")
execute_all_with_nosetests(test_list)
将带有“ INSERT”的字符串替换到您自己的文件夹中。另外,需要更正execute_all_with_nosetests函数。 我没有运行它,但这是我的测试运行脚本的下标。
答案 1 :(得分:1)
如果按以下方式执行测试,则应执行目录中的所有测试,包括子目录:
nosetests --reset-db --nologcapture --with-pylons=test-core.ini ckan.tests.legacy -s -v
希望这会有所帮助