Skip to content

Commit

Permalink
Update 2023-07-17-pytest学习.md
Browse files Browse the repository at this point in the history
  • Loading branch information
shihai1991 committed Aug 22, 2023
1 parent e93fe41 commit 057412f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion _posts/2023-07-17-pytest学习.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ fixture可以用于初始化测试函数,它们提供固定的基线,以便
Failed: Fixture "fixture_name" called directly. Fixtures are not meant to be called directly
```

##
## Function

## Session

## FixtureDef
在执行测试中,测试函数通过执行`fixturedef = request._get_active_fixturedef(argname)`来反查参数对应的fixutre,[代码详情](https://github.com/pytest-dev/pytest/blob/37bb1861757685acca09455d63aa148a65317989/src/_pytest/fixtures.py#L1137)
`class Function`是对测试函数的封装,所有的准备及执行动作都在这个类实例中完成,如:通过参数找fixtures的过程就是在`def setup()`中执行完成的。
这里的`Function`对象实例实际在`Session`实例化过程中生成了所有的`Function`对象,这个执行动作是由`main.pytest_collection()`函数触发的,而真正的遍历函数是`Session.genitems()`,比如我要执行一个test.py文件,则会触发`session.genitems("test.py")`并创建出所有的Function对象实例。
Expand Down

0 comments on commit 057412f

Please sign in to comment.