-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
922b070
commit dfebb52
Showing
4 changed files
with
1,315 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture( | ||
scope="session", | ||
params=[ | ||
{ | ||
"val": "a2", | ||
"wei": "a1", | ||
"exp": "a1", | ||
"axis": "a0", | ||
}, | ||
{ | ||
"val": "b2", | ||
"wei": "b2", | ||
"exp": "b1", | ||
"axis": "b1", | ||
}, | ||
{ | ||
"val": "c3", | ||
"wei": "c2", | ||
"exp": "c1", | ||
"axis": "c0", | ||
}, | ||
{ | ||
"val": "d2", | ||
"wei": "d2", | ||
"exp": "d1", | ||
"axis": "d1", | ||
}, | ||
], | ||
) | ||
def complexcases(request): | ||
return request.param | ||
|
||
|
||
@pytest.fixture( | ||
scope="session", | ||
params=[ | ||
{ | ||
"val": "e1", | ||
"wei": "e1", | ||
"exp": "e0", | ||
}, | ||
{ | ||
"val": "f1", | ||
"wei": "f1", | ||
"exp": "f0", | ||
}, | ||
{ | ||
"val": "g1", | ||
"wei": "g1", | ||
"exp": "g0", | ||
}, | ||
{ | ||
"val": "h1", | ||
"wei": "h0", | ||
"exp": "h2", | ||
}, | ||
], | ||
) | ||
def easycases(request): | ||
return request.param | ||
|
||
|
||
@pytest.fixture | ||
def val2d(easycases, complexcases): | ||
allcases = [easycases] + [complexcases] | ||
values = [cas["val"] for cas in allcases] | ||
return [val for val in values if val[1] == "2"] | ||
|
||
|
||
@pytest.fixture | ||
def val1d(easycases, complexcases): | ||
allcases = [*easycases, *complexcases] | ||
return [case["val"] for case in allcases if case["val"][1] == "1"] | ||
|
||
|
||
@pytest.fixture | ||
def val0d(easycases, complexcases): | ||
allcases = [*easycases, *complexcases] | ||
return [case["val"] for case in allcases if case["val"][1] == "0"] | ||
|
||
|
||
def test_two_d_cases(val2d): | ||
print(val2d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# I have a pytest integer fixture fix1 which is parametrized with the values 1,2,3, and another pytest integer fixture fix2 which is parametrized with the values 10,11, 20. I want to create a fixture fix3 which returns every value for fix1 and for fix2, one after the other, as long as the value is odd. So, fix3 should return the integer values 1, then 3, then 11. How do I do that? | ||
|
||
import pytest | ||
|
||
|
||
# Define fixture for `fix1` | ||
@pytest.fixture(params=[[1], [2], [3]]) | ||
def alist(request): | ||
return request.param | ||
|
||
|
||
# Define fixture for `fix2` | ||
@pytest.fixture(params=[9, 10, 11]) | ||
def anelement(request): | ||
return request.param | ||
|
||
|
||
def test_1(anelement): | ||
print(f"test_1: {anelement:=}") | ||
|
||
|
||
@pytest.fixture | ||
def longer_list(alist, anelement): | ||
alist.append(anelement) | ||
|
||
|
||
def test_listcontent(longer_list): | ||
print("---".join(longer_list)) |
Oops, something went wrong.