- pytest Quick Start Guide
- Bruno Oliveira
- 135字
- 2021-07-16 17:51:27
Powerful asserts
As you've probably already noticed, pytest makes use of the built-in assert statement to check assumptions during testing. Contrary to other frameworks, you don't need to remember various self.assert* or self.expect* functions. While this may not seem like a big deal at first, after spending some time using plain asserts, you will realize how much that makes writing tests more enjoyable and natural.
Again, here's an example of a failure:
________________________ test_default_health ________________________
def test_default_health():
health = get_default_health('warrior')
> assert health == 95
E assert 80 == 95
tests\test_assert_demo.py:25: AssertionError
Pytest shows the line of the failure, as well as the variables and expressions involved in the failure. By itself, this would be pretty cool already, but pytest goes a step further and provides specialized explanations of failures involving other data types.
推薦閱讀
- 解析QUIC/HTTP3:未來互聯(lián)網(wǎng)的基石
- FreeSWITCH 1.2
- GPS/GNSS原理與應(yīng)用(第3版)
- 網(wǎng)絡(luò)的琴弦:玩轉(zhuǎn)IP看監(jiān)控
- 電力物聯(lián)網(wǎng)工程技術(shù)原理與應(yīng)用
- IPv6網(wǎng)絡(luò)切片:使能千行百業(yè)新體驗
- OMNeT++與網(wǎng)絡(luò)仿真
- Echo Quick Start Guide
- 物聯(lián)網(wǎng)場景設(shè)計與開發(fā)(初級)
- Microsoft Power Platform Enterprise Architecture
- bash網(wǎng)絡(luò)安全運(yùn)維
- 精通SEO:100%網(wǎng)站流量提升密碼
- Python API Development Fundamentals
- 區(qū)塊鏈技術(shù)與應(yīng)用:打造分布式商業(yè)新生態(tài)
- 黑客與反黑工具使用詳解