最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Fixture `record_property` not found - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论