简体   繁体   English

鼻子测试-在子目录中运行所有测试

[英]nosetest - run all tests in subdirectories

I am running the nosetest command below but it only runs the tests in the first folder, i have extra tests in subdirectories. 我在下面运行鼻子测试命令,但它仅在第一个文件夹中运行测试,我在子目录中有其他测试。 How do you edit the command to run all the following tests in all subdirectories of the folder i specified? 如何编辑命令以在我指定的文件夹的所有子目录中运行以下所有测试?

nosetests -s -v --ckan --with-pylons=test-core.ini ckan/tests/legacy/*

Here is the basic structure of the tests in the following directory 这是以下目录中测试的基本结构

https://github.com/ckan/ckan/tree/ckan-2.7.3/ckan/tests/legacy https://github.com/ckan/ckan/tree/ckan-2.7.3/ckan/tests/legacy

You can write script that do generation of all required paths. 您可以编写脚本来生成所有必需的路径。

I use something as: 我用作为:

#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)

Replace strings with "INSERT" to your own folders. 将字符串替换为“ INSERT”到您自己的文件夹中。 Also, correction of execute_all_with_nosetests function is needed. 另外,需要更正execute_all_with_nosetests函数。 I don't run it, but it is subscript of my test running script. 我没有运行它,但这是我的测试运行脚本的下标。

You should execute all the test in the directory including the sub-directories if you execute the tests as: 如果按照以下方式执行测试,则应执行目录中包括子目录的所有测试:

nosetests --reset-db --nologcapture --with-pylons=test-core.ini ckan.tests.legacy -s -v

Hope this will help 希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM