doctest 的 setup

# doctest 的 setup

在项目中写了 doctest,但是需要先初始化环境才方便使用。

在运行 pytest 的目录下创建conftest.py

#!/usr/bin/python3
# encoding: utf-8 
# @author  : zza
# @File    : conftest.py
""" FOR DOCTEST """
import pytest

@pytest.fixture(autouse=True)
def init_env(doctest_namespace):
    print("doctest_namespace", doctest_namespace)
    import os
    sql_url = "sqlite:///data.db"
    os.environ['sql_uri'] = sql_url
    init(sql_url)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  • pytest 启动就用 pytest 命令就好了:pytest
  • coverage 启动时使用该命令启动:coverage run --source my_pachage -m pytest

更多使用案例建议 github 直接 搜索conftest.py文件。 (opens new window)

上次更新: 2024-01-10 16:01:00
最近更新
01
自建 RSS 订阅
01-05
02
搭建私人 docker hub
01-02
03
关于 SSH 攻击
10-12
更多文章>