我是Python新手,正在使用pytest进行测试
我从python脚本中执行pytest。我在脚本中有一个全局变量,我根据测试结果对其进行了修改。执行测试后,将再次使用更新后的全局变量。
import pytest
global test_suite_passed
test_suite_passed = True
def test_toggle():
global test_suite_passed
a = True
b = True
c = True if a == b else False
test_suite_passed = c
assert c
我使用pytest覆盖率,下面命令行中有测试脚本,这些脚本将为我生成覆盖率报告:
"""Manager script to run the commands on the Flask API."""
import os
import click
from api import create_app
from briqy.logHelper import b as logger
import pytest
app = create_app()
@app.cli.command("tests")
@click.argument(
在下面的示例中,如何将args of run_tests()传递给pytest.main(...),以便在TestFooBar In test_module.py的测试方法中使用args
my_module.py
def run_tests(args):
# How do I pass parameter 'args' to pytest here.
pytest.main(['-q', '-s', 'test_module.py::TestFooBar'])
test_module.py
class TestFo
我从来没把这件事搞清楚。我认为这个if语句所做的是允许函数在调用时运行,而不是在导入它所用的模块时运行。以以下代码为例:
# Finds duplicate values in a specified feature class field and populates those reords with a 'Y' in another field
import arcpy
# enter program inputs
def findDupes(inFeatureClass, checkField, updateField, countRec = 0):
with
是否有一种方法来抑制pytest的内部反对警告?
上下文:我希望评估将测试套件从nose移植到pytest的困难。该套件相当大,并且大量使用基于nose-style yield的测试生成器。
我希望首先确保现有的测试通过pytest,然后可能将测试生成器更改为parameterized。
使用pytest 3.0.4运行$ pytest path-to-test-folder完全由
WC1 ~repos/numpy/numpy/lib/tests/test_twodim_base.py yield tests are deprecated, and scheduled to be remove