python - Fixture `record_property` not found - Stack Overflow

I'm trying to use the record_property fixture (.html#record-property). My build file looks like th

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
  • Note: I did try changing unittest.main... to pytest.main([__file__]) but the problem persists. – Stephen Gross Commented Nov 19, 2024 at 21:30
Add a comment  | 

1 Answer 1

Reset to default 0

You 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742397392a4436222.html

相关推荐

  • python - Fixture `record_property` not found - Stack Overflow

    I'm trying to use the record_property fixture (.html#record-property). My build file looks like th

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信