大熊猫库中的测试:为什么选择基于类的测试而选择功能样式?

发布于 2025-01-26 12:35:11 字数 352 浏览 1 评论 0原文

为什么功能样式的测试与基于类的测试相比促进测试?这只是其他图书馆的特定功能,还是有任何一般理由采用功能样式测试模式?

引用

PANDAS现有的测试结构主要基于类,这意味着您通常会找到包裹在类中的测试。

class TestReallyCoolFeature:  
    pass

展望未来,我们正在使用Pytest Framework进入更具功能的样式,该框架提供了更丰富的测试框架,可以促进测试和开发。因此,我们将不用编写测试类,而是以这样的方式编写测试功能:

def test_really_cool_feature():
    pass

Why is functional style testing facilitating testing compared to class based testing? Is this just additional library specific functionality or are there any general reasons to adopt functional style testing patterns?

To quote from pandas development guidelines:

pandas existing test structure is mostly class-based, meaning that you will typically find tests wrapped in a class.

class TestReallyCoolFeature:  
    pass

Going forward, we are moving to a more functional style using the pytest framework, which offers a richer testing framework that will facilitate testing and developing. Thus, instead of writing test classes, we will write test functions like this:

def test_really_cool_feature():
    pass

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

儭儭莪哋寶赑 2025-02-02 12:35:11

pr评论。简而言之,从基于类的测试到基于功能的测试的转变是熊猫从鼻子转变为pytest的结果。

在开关之前,几乎每个测试都是unittest.testcase的子类的方法。 PYTEST在运行Unittest测试方面有很好的支持,但是有一些pytest功能无法在unittest.testcase.testcase.testcase sublasses中使用。这些不兼容的功能在 pytest文档。其中之一是@pytest.mark.mark.parametrize。正如公关评论所解释的那样,使用@pytest.mark.parametrize的愿望激发了测试样式的变化。

There's an explanation in this PR comment. In short, the move from class-based testing to function-based testing is a consequence of pandas switching from nose to pytest.

Before the switch, almost every test was a method of a subclass of unittest.TestCase. pytest has very good support for running unittest tests, but there are some pytest features that can't be used inside unittest.TestCase subclasses. These incompatible features are listed in the pytest docs. One of them is @pytest.mark.parametrize. As the PR comment explains, the desire to use @pytest.mark.parametrize motivated the change in testing style.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文