|
1 | 1 | # -*- coding: utf-8 -*- |
| 2 | +import copy |
2 | 3 | import sys |
3 | 4 | import types |
4 | 5 | from collections import defaultdict |
5 | 6 | import pytest |
6 | | -from _pytest.fixtures import scopenum_function |
7 | 7 |
|
8 | 8 |
|
9 | 9 | PY3 = sys.version_info[0] == 3 |
@@ -79,30 +79,21 @@ def normalize_metafunc_calls(metafunc, valtype): |
79 | 79 | metafunc._calls = newcalls |
80 | 80 |
|
81 | 81 |
|
| 82 | +def copy_metafunc(metafunc): |
| 83 | + copied = copy.copy(metafunc) |
| 84 | + copied.fixturenames = copy.copy(metafunc.fixturenames) |
| 85 | + copied._calls = [] |
| 86 | + copied._ids = copy.copy(metafunc._ids) |
| 87 | + copied._arg2fixturedefs = copy.copy(metafunc._arg2fixturedefs) |
| 88 | + return copied |
| 89 | + |
| 90 | + |
82 | 91 | def parametrize_callspecs(callspecs, metafunc, fname, fparams): |
83 | | - allnewcallspecs = [] |
84 | | - for i, param in enumerate(fparams): |
85 | | - try: |
86 | | - newcallspecs = [call.copy() for call in callspecs] |
87 | | - except TypeError: |
88 | | - # pytest < 3.6.3 |
89 | | - newcallspecs = [call.copy(metafunc) for call in callspecs] |
90 | | - |
91 | | - # TODO: for now it uses only function scope |
92 | | - # TODO: idlist |
93 | | - setmulti_args = ( |
94 | | - {fname: 'params'}, (fname,), (param,), |
95 | | - None, (), scopenum_function, i |
96 | | - ) |
97 | | - try: |
98 | | - for newcallspec in newcallspecs: |
99 | | - newcallspec.setmulti2(*setmulti_args) |
100 | | - except AttributeError: |
101 | | - # pytest < 3.3.0 |
102 | | - for newcallspec in newcallspecs: |
103 | | - newcallspec.setmulti(*setmulti_args) |
104 | | - allnewcallspecs.extend(newcallspecs) |
105 | | - return allnewcallspecs |
| 92 | + newmetafunc = copy_metafunc(metafunc) |
| 93 | + newmetafunc._calls = callspecs |
| 94 | + newmetafunc.fixturenames.append(fname) |
| 95 | + newmetafunc.parametrize(fname, fparams, indirect=True) |
| 96 | + return newmetafunc._calls |
106 | 97 |
|
107 | 98 |
|
108 | 99 | def normalize_call(callspec, metafunc, valtype, used_keys=None): |
|
0 commit comments