簡體   English   中英

帶有pytest標記的python腳本的Sphinx文檔

[英]Sphinx documentation of python script with pytest marker

我一直在尋找使用Sphinx記錄使用pytest的測試模塊的方法。 在腳本中有用戶定義的pytest.mark。 有沒有一種方法可以配置Sphinx或.rst模板文件以包含pytest.mark定義,即使它們在docstring之外?

有關使用:regexp:的sphinx文檔非常含糊,我無法找到使用它的良好示例。

Python 2.7.6 Sphinx構建1.3.3

"""
    script: test_sample.py
    :Test Description: Simple test to show function of py.test and sphinx doc
    :Author: James Brown
    Requirement ID: Test1234
"""
import sys
from sys import argv
import re
import pytest


pytestmark = [
    pytest.mark.author("jbrown"),
    pytest.mark.req("test-001"),
    pytest.mark.testtype("Full"),
    pytest.mark.mat0]

blah = """
    blah
    blah
    blah
"""


def func(x):
    """
        Returns an integer incremented by one
    """

    return x + 1

def test_answer():
    """
        Checks if value equals 5
    """
    assert func(3) == 5

第一個文件添加

.. exec::
    import re
    from src.test_samplepytest import pytestmark

    attre = re.compile(r"\'(\w+)\'.*\(\'?(\w*)")

    for value in pytestmark:
        mark = str(value)
        att = attre.search(mark)
        if att.group(2):
            print "{:<10}: {:<15}\n".format(att.group(1),att.group(2))
        else:
            print "{:<10}: \n".format(att.group(1))'

我選擇為測試腳本編寫一個文件解析器。 這將運行驗證,pylint等,並將有趣的信息加載到數據庫表中。

然后,我可以查詢數據庫,並使用https://pypi.python.org/pypi/tabulate返回格式化的表。

sphinx rst文件包含:

  5     .. exec::                                                                  
  6         dbquery('col1,col2,col3','test_moduleName',db='my_database')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM