nosetest - 运行 子目录中的所有测试
nosetest - run all tests in subdirectories
我正在 运行ning 下面的 nosetest 命令,但它只 运行 第一个文件夹中的测试,我在子目录中有额外的测试。您如何编辑命令以 运行 在我指定的文件夹的所有子目录中进行以下所有测试?
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
您可以编写脚本来生成所有必需的路径。
我用的是:
#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 函数。
我没有运行,但它是我测试运行ning脚本的下标。
如果执行测试,则应执行目录(包括子目录)中的所有测试:
nosetests --reset-db --nologcapture --with-pylons=test-core.ini ckan.tests.legacy -s -v
希望这会有所帮助
我正在 运行ning 下面的 nosetest 命令,但它只 运行 第一个文件夹中的测试,我在子目录中有额外的测试。您如何编辑命令以 运行 在我指定的文件夹的所有子目录中进行以下所有测试?
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
您可以编写脚本来生成所有必需的路径。
我用的是:
#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 函数。 我没有运行,但它是我测试运行ning脚本的下标。
如果执行测试,则应执行目录(包括子目录)中的所有测试:
nosetests --reset-db --nologcapture --with-pylons=test-core.ini ckan.tests.legacy -s -v
希望这会有所帮助