大熊猫库中的测试:为什么选择基于类的测试而选择功能样式?
为什么功能样式的测试与基于类的测试相比促进测试?这只是其他图书馆的特定功能,还是有任何一般理由采用功能样式测试模式?
引用
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此 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 runningunittest
tests, but there are some pytest features that can't be used insideunittest.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.