对于在CI中运行的测试,应使用pytest吗?为什么?

huangapple go评论80阅读模式
英文:

What to tests in ci run vs pytest, and why

问题

使用ci.yml文件中的run方式主要适用于持续集成(CI),通常用于自动化构建和部署流程。这种方式适合执行集成测试、部署前的自动化检查等任务。

另一种方式是在名为test的文件夹下创建test_...文件,并通过运行pytest tests在CI流水线中执行它们。这适合单元测试、功能测试等更细粒度的测试,通常用于检查代码中的特定功能或组件。

选择哪种方式取决于您的测试需求和工作流程。持续集成中的run方式适合执行整体集成和自动化检查,而pytest方式适合更详细的测试用例。

英文:

I have a python repo in github. If I understood it correctly there are mainly two ways in which tests can be automated:

  • using run in a ci.yml file
  • using test_... files under a folder called test (at root level) and then execute them in the ci pipeline by running pytest tests

What type of tests are more suitable for each of these options? And why?

答案1

得分: 0

PyTest:pytest非常适用于编写和执行单元测试,并在CI流水线中常常包括使用pytest编写的单元测试。单元测试侧重于“在隔离的情况下测试单个组件或代码单元”。它们有助于验证每个代码单元的功能是否正确,是否符合其预期行为。这些测试通常执行速度更快,并提供有关单个代码单元正确性的即时反馈。

CI测试:集成测试旨在测试“系统中不同组件如何协同工作”。它们验证各种代码单元之间的集成点和交互是否正常工作。集成测试在捕获可能由系统不同部分之间的交互引发的问题方面非常有价值。

英文:

Nvm, I found this:

PyTest: pytest is well-suited for writing and executing unit tests, and it's common to include unit tests written with pytest in the CI pipeline. Unit tests are focused on testing individual components or units of code in isolation. They help verify that each unit of code functions correctly and meets its expected behavior. These tests are typically faster to execute and provide immediate feedback on the correctness of individual units of code.

CI Tests: Integration tests are designed to test how different components of a system work together. They verify that the integration points and interactions between various units of code function correctly. Integration tests are valuable in catching issues that may arise due to interactions between different parts of the system.

huangapple
  • 本文由 发表于 2023年5月22日 06:32:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76302191.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定