File: call_count.md

package info (click to toggle)
python-flexmock 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 460 kB
  • sloc: python: 3,802; makefile: 17; sh: 14
file content (34 lines) | stat: -rw-r--r-- 928 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Asserting call counts

Using the `times(N)` modifier, or its aliases (`once`, `twice`, or `never`)
allows you to create call count expectations that will be automatically checked
by the test runner.

!!! note

    If you do not provide `times` modifier. The mock is expected to be called
    zero or any number of times. In other words, the call count is not asserted.

Ensure `fly("forward")` gets called exactly three times

```python
flexmock(plane).should_receive("fly").with_args("forward").times(3)
```

Ensure `turn("east")` gets called at least twice:

```python
flexmock(plane).should_receive("turn").with_args("east").at_least().twice()
```

Ensure `land("airfield")` gets called at most once:

```python
flexmock(plane).should_receive("land").with_args("airfield").at_most().once()
```

Ensure that `crash("boom!")` is never called:

```python
flexmock(plane).should_receive("crash").with_args("boom!").never()
```