File: multiple_return.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 (32 lines) | stat: -rw-r--r-- 660 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
# Multiple return values

It is possible for the mocked method to return different values on successive
calls:

```python
>>> flexmock(group).should_receive("get_member").and_return("user1").and_return(
    "user2"
).and_return("user3")
>>> group.get_member()
"user1"
>>> group.get_member()
"user2"
>>> group.get_member()
"user3"
```

Or use the short-hand form

```python
flexmock(group).should_receive("get_member").and_return(
    "user1", "user2", "user3"
).one_by_one()
```

You can also mix return values with exception raises

```python
flexmock(group).should_receive("get_member").and_return("user1").and_raise(
    Exception
).and_return("user2")
```