pytest-mock 项目教程

pytest-mock 项目教程

pytest-mockThin-wrapper around the mock package for easier use with pytest项目地址:https://gitcode.com/gh_mirrors/py/pytest-mock

1. 项目的目录结构及介绍

pytest-mock/
├── docs/
│   ├── conf.py
│   ├── index.rst
│   └── ...
├── src/
│   └── pytest_mock/
│       ├── __init__.py
│       └── plugin.py
├── tests/
│   ├── __init__.py
│   └── test_plugin.py
├── .gitignore
├── .pre-commit-config.yaml
├── CHANGELOG.rst
├── LICENSE
├── README.rst
├── pyproject.toml
├── tox.ini
└── ...
  • docs/: 包含项目的文档文件,使用 Sphinx 生成文档。
    • conf.py: Sphinx 配置文件。
    • index.rst: 文档的主索引文件。
  • src/pytest_mock/: 包含项目的主要源代码。
    • init.py: 模块初始化文件。
    • plugin.py: 插件的主要实现文件。
  • tests/: 包含项目的测试代码。
    • init.py: 测试模块初始化文件。
    • test_plugin.py: 针对插件的测试文件。
  • .gitignore: Git 忽略文件配置。
  • .pre-commit-config.yaml: 预提交钩子配置文件。
  • CHANGELOG.rst: 项目变更日志。
  • LICENSE: 项目许可证文件。
  • README.rst: 项目说明文件。
  • pyproject.toml: 项目配置文件,包含构建系统和依赖管理。
  • tox.ini: 多环境测试配置文件。

2. 项目的启动文件介绍

项目的启动文件主要是 src/pytest_mock/plugin.py,这个文件包含了 pytest-mock 插件的主要实现逻辑。它定义了 mocker fixture,用于在测试中进行 mocking 操作。

# src/pytest_mock/plugin.py

import pytest
from _pytest.monkeypatch import MonkeyPatch

@pytest.fixture
def mocker():
    return MonkeyPatch()

3. 项目的配置文件介绍

  • pyproject.toml: 这个文件是项目的核心配置文件,包含了构建系统、依赖管理和其他项目配置。
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "pytest-mock"
version = "3.14.0"
description = "Thin-wrapper around the mock package for easier use with pytest"
authors = [
    { name="Bruno Oliveira" }
]
license = { file="LICENSE" }
dependencies = [
    "pytest>=6.0.0",
    "mock>=4.0.0"
]
  • tox.ini: 这个文件用于配置多环境测试,确保项目在不同 Python 版本和环境中都能正常运行。
[tox]
envlist = py38, py39, py310, py311

[testenv]
deps =
    pytest
    mock
commands =
    pytest

通过这些配置文件,可以确保项目在不同环境和版本中都能稳定运行,并且易于维护和扩展。

pytest-mockThin-wrapper around the mock package for easier use with pytest项目地址:https://gitcode.com/gh_mirrors/py/pytest-mock

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

成婕秀Timothy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值