【问题标题】:pytest "fixture 'url' not found" while no fixture is usedpytest“未找到夹具'url'”而没有使用夹具
【发布时间】:2020-06-08 19:20:19
【问题描述】:

当我尝试执行测试 (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
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_xml_property, recwarn, tmpdir, tmpdir_factory, worker_id
>       use 'pytest --fixtures [testpath]' for help on them.

/usr/local/lib/python3.6/site-packages/allure_commons/_allure.py:50
=========================== 1 error in 0.40 seconds ============================

但我没有在代码中使用任何“url”夹具。 我什至尝试重命名项目中的每个“url”变量,但问题仍然存在。

安装要求:

allure-pytest==2.8.16
allure-python-commons==2.8.16
atomicwrites==1.4.0
attrs==19.3.0
axe-selenium-python==2.1.6
certifi==2020.4.5.2
chardet==3.0.4
colorama==0.4.3
configparser==5.0.0
coverage==5.1
crayons==0.3.1
cx-Oracle==7.3.0
Faker==4.1.0
flaky==3.6.1
idna==2.9
importlib-metadata==1.6.1
iso3166==1.0.1
more-itertools==8.3.0
packaging==20.4
page-objects==1.1.0
parameterized==0.7.4
pluggy==0.13.1
py==1.8.1
pycountry==19.8.18
pyparsing==2.4.7
pytest==5.4.3
python-dateutil==2.8.1
PyYAML==5.3.1
requests==2.23.0
schwifty==2020.5.3
selenium==3.141.0
simple-value-object==1.3
six==1.15.0
text-unidecode==1.3
urllib3==1.25.9
wcwidth==0.2.4
webdriver-manager==2.5.3
zipp==3.1.0

【问题讨论】:

  • 您执行测试的当前目录是什么?是/吗?
  • 是的,我的代码结构类似于:base_dir/src/project1/tests/my_test.py

标签: python automated-tests pytest allure


【解决方案1】:

[更新] 我终于找到了解决方案。事实证明,我必须将__test__ = True 添加到我的测试类中。

仅供参考:我所有的测试都继承自 TestBase(unittest.TestCase) 类 它具有属性__test__ = False。此属性的目的是不重复测试执行 - 一次来自基类,第二次来自继承类。 更多详情:https://www.termitnjak.com/en/blog/pytest-inheritance-problems

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 2021-10-01
    • 1970-01-01
    • 2019-07-17
    • 2020-12-17
    • 1970-01-01
    • 2022-01-21
    相关资源
    最近更新 更多