admin管理员组文章数量:1335895
I'm trying to use the record_property
fixture (.html#record-property). My build file looks like this:
load("@pip//:requirements.bzl", "requirement")
py_test(
name = "test_foo",
srcs = ["test_foo.py"],
deps = [
requirement("pytest"),
],
)
And test_foo.py
looks like this:
import pytest
import unittest
from unittest import TestCase
class TestFoo(TestCase):
def test_escape(self, record_property):
pass
if __name__ == "__main__":
unittest.main()
When I run the test (bazel test //path/to:test_foo
), I get an error about the record_property
fixture being undefined:
TypeError: test_escape() missing 1 required positional argument: 'record_property'
I suspect this is due to some nuance in my build rule, bazel invocation, or Python set up. I've researched this a bit, and it does sound like other folks have encountered "missing fixture" errors, though not this flavor in particular. Any pointers are appreciated :)
I'm trying to use the record_property
fixture (https://docs.pytest./en/stable/reference/reference.html#record-property). My build file looks like this:
load("@pip//:requirements.bzl", "requirement")
py_test(
name = "test_foo",
srcs = ["test_foo.py"],
deps = [
requirement("pytest"),
],
)
And test_foo.py
looks like this:
import pytest
import unittest
from unittest import TestCase
class TestFoo(TestCase):
def test_escape(self, record_property):
pass
if __name__ == "__main__":
unittest.main()
When I run the test (bazel test //path/to:test_foo
), I get an error about the record_property
fixture being undefined:
TypeError: test_escape() missing 1 required positional argument: 'record_property'
I suspect this is due to some nuance in my build rule, bazel invocation, or Python set up. I've researched this a bit, and it does sound like other folks have encountered "missing fixture" errors, though not this flavor in particular. Any pointers are appreciated :)
Share Improve this question asked Nov 19, 2024 at 21:28 Stephen GrossStephen Gross 5,72412 gold badges43 silver badges59 bronze badges 1 |1 Answer
Reset to default 0You can't use pytest fixtures in this way with unittest.TestCase
classes. From https://docs.pytest./en/stable/how-to/unittest.html:
unittest.TestCase methods cannot directly receive fixture arguments as implementing that is likely to inflict on the ability to run general unittest.TestCase test suites.
The above usefixtures and autouse examples should help to mix in pytest fixtures into unittest suites.
You can also gradually move away from subclassing from unittest.TestCase to plain asserts and then start to benefit from the full pytest feature set step by step.
本文标签: pythonFixture recordproperty not foundStack Overflow
版权声明:本文标题:python - Fixture `record_property` not found - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742397392a2467199.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
unittest.main...
topytest.main([__file__])
but the problem persists. – Stephen Gross Commented Nov 19, 2024 at 21:30