我正在为一个web应用程序构建一个测试套件。我使用的固定装置如下:
import pytest
from selenium import webdriver
from common import Common
@pytest.fixture(scope='module')
def driver(module, headless=True):
opts = webdriver.FirefoxOptions()
opts.add_argument('--headless') if headless else None
driver = we
当我尝试执行测试(python3 -m pytest dir1/subdir/test.py)时,我得到错误:
__________________________ ERROR at setup of testcase __________________________
file /usr/local/lib/python3.6/site-packages/allure_commons/_allure.py, line 50
def testcase(url, name=None):
E fixture 'url' not found
> a
我有一个项目,每个应用程序都有一个tests模块,如下所示:
app1/
tests/
__init__.py
# whatever test files are
app2/
tests/
__init__.py
# whatever test files are
在项目根目录中也有您可以猜到的项目包。它有一个testing子包,它包含模型和字段的基本测试用例,当然还有如下所示的固定装置:
myproject/
__init__.py
# settings and related files, you know
testing/
__
当我运行pylint pylint-pytest plugin cannot enumerate and collect pytest fixtures. Please run `pytest --fixtures --collect-only path/to/current/module.py` and resolve any potential syntax error or package dependency issues (Can-enumerate-pytest-fixtures)时,您能解释一下提示‘pylint-pytest plugin cannot enumerate an
是否可以禁用pytest中的fixture?
我想这样做的原因是我正在使用我自己的fixtures框架,目前就像这样(不同fixtures机制的优缺点不是这个问题的焦点):
import functools
def with_fixtures(test_func):
@functools.wraps(test_func)
def wrapper(self, *args, **kwargs):
# This simplified code reproduces the problem -- the real implementation passes
当其中一个包含构造函数参数时,我会知道如何加载所有的夹具。
现在,我使用此方法加载所有固定装置:
/**
* @return string[]
* @codeCoverageIgnore
* load all fixtures in the good order regarding relations
*/
// Names are samples
public function getDependencies()
{
return [
UserFixture::class,
AAAFixture::class,
BBBF
我正在尝试将py.test的与我的单元测试结合在一起,与unittest一起使用。我在项目的顶层(如描述的)将几个夹具放在conftest.py文件中,用@pytest.fixture装饰它们,并将它们的名称作为需要它们的测试函数的参数。
安装程序注册正确,如py.test --fixtures test_stuff.py所示,但是当我运行py.test时,我得到了NameError: global name 'my_fixture' is not defined。这似乎只有在我使用unittest.TestCase-but的子类时才会发生-- py.test文档似乎说它与un
我一直在使用库来模拟pytest。当我试图使用tox命令运行测试时,我得到了以下错误:
...
tests/test_cli.py ....EEEE
...
file /path/to/test_cli.py, line 63
def test_cli_with_init_cmd_fails_with_db_error(runner, mocker, context):
E fixture 'mocker' not found
> available fixtures: cache, capfd, capfdbinary, caplog, ca
我在测试文件中定义了以下fixture: import os
from dotenv import load_dotenv, find_dotenv
from packaging import version # for comparing version numbers
load_dotenv(find_dotenv())
VERSION = os.environ.get("VERSION")
API_URL = os.environ.get("API_URL")
@pytest.fixture()
def skip_before_version():
我想在conftest.py中设置一个固定设备,并与我的所有测试共享它。但是,在下面的最小示例中运行pytest时,我会遇到以下错误:
ERROR at setup of test_test
Fixture "pytest_runtest_setup" called directly. Fixtures are not meant to be called directly,
but are created automatically when test functions request them as parameters.
conftest.py
import pyte