Skip to content

Commit 5befce8

Browse files
committed
Workaround to get ipytest play nicely with 3.11
See chmp/ipytest#93
1 parent 33150e0 commit 5befce8

3 files changed

Lines changed: 11 additions & 32 deletions

File tree

notebooks/beginner/notebooks/08_testing1.ipynb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"metadata": {},
7979
"outputs": [],
8080
"source": [
81-
"# This would be in your e.g. implementation.py\n",
8281
"def sum_of_three_numbers(num1, num2, num3):\n",
8382
" return num1 + num2 + num3"
8483
]
@@ -102,11 +101,7 @@
102101
"outputs": [],
103102
"source": [
104103
"%%ipytest\n",
105-
"# Mention this at the top of cells which contain test(s)\n",
106-
"# This is only required for running pytest in Jupyter notebooks\n",
107104
"\n",
108-
"\n",
109-
"# This would be in your test_implementation.py\n",
110105
"def test_sum_of_three_numbers():\n",
111106
" # 1. Setup the variables used in the test\n",
112107
" num1 = 2\n",
@@ -144,7 +139,7 @@
144139
"name": "python",
145140
"nbconvert_exporter": "python",
146141
"pygments_lexer": "ipython3",
147-
"version": "3.10.3"
142+
"version": "3.11.0"
148143
}
149144
},
150145
"nbformat": 4,

notebooks/beginner/notebooks/16_testing2.ipynb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"metadata": {},
4141
"outputs": [],
4242
"source": [
43-
"# This would be e.g. in person.py\n",
4443
"class Person:\n",
4544
" def __init__(self, first_name, last_name, age):\n",
4645
" self.first_name = first_name\n",
@@ -74,7 +73,6 @@
7473
"metadata": {},
7574
"outputs": [],
7675
"source": [
77-
"# This would be in either conftest.py or test_person.py\n",
7876
"import pytest\n",
7977
"\n",
8078
"\n",
@@ -99,7 +97,7 @@
9997
"source": [
10098
"%%ipytest\n",
10199
"\n",
102-
"# These would be in test_person.py\n",
100+
"\n",
103101
"def test_full_name(default_person): # Note: we use fixture as an argument of the test case\n",
104102
" result = default_person.full_name\n",
105103
" assert result == 'John Doe'\n",
@@ -147,7 +145,6 @@
147145
"metadata": {},
148146
"outputs": [],
149147
"source": [
150-
"# This would be e.g. in string_manipulate.py\n",
151148
"def replace_names(original_str, new_name):\n",
152149
" \"\"\"Replaces names (uppercase words) of original_str by new_name\"\"\"\n",
153150
" words = original_str.split()\n",
@@ -170,7 +167,7 @@
170167
"source": [
171168
"%%ipytest\n",
172169
"\n",
173-
"# This would be in your test module\n",
170+
"\n",
174171
"@pytest.mark.parametrize(\"original,new_name,expected\", [\n",
175172
" ('this is Lisa', 'John Doe', 'this is John Doe'),\n",
176173
" ('how about Frank and Amy', 'John', 'how about John and John'),\n",
@@ -180,13 +177,6 @@
180177
" result = replace_names(original, new_name)\n",
181178
" assert result == expected"
182179
]
183-
},
184-
{
185-
"cell_type": "code",
186-
"execution_count": null,
187-
"metadata": {},
188-
"outputs": [],
189-
"source": []
190180
}
191181
],
192182
"metadata": {
@@ -205,7 +195,7 @@
205195
"name": "python",
206196
"nbconvert_exporter": "python",
207197
"pygments_lexer": "ipython3",
208-
"version": "3.10.3"
198+
"version": "3.11.0"
209199
}
210200
},
211201
"nbformat": 4,

notebooks/intermediate/notebooks/01_pytest_fixtures.ipynb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,18 @@
8383
"metadata": {},
8484
"outputs": [],
8585
"source": [
86+
"%%ipytest -s\n",
87+
"\n",
88+
"\n",
8689
"@pytest.fixture\n",
8790
"def my_fixture():\n",
8891
" print(\"\\nmy_fixture is used\")\n",
89-
"\n",
92+
" \n",
9093
"\n",
9194
"@pytest.fixture\n",
9295
"def other_fixture():\n",
93-
" return \"FOO\""
94-
]
95-
},
96-
{
97-
"cell_type": "code",
98-
"execution_count": null,
99-
"metadata": {},
100-
"outputs": [],
101-
"source": [
102-
"%%ipytest -s\n",
96+
" return \"FOO\"\n",
97+
"\n",
10398
"\n",
10499
"@pytest.mark.usefixtures('my_fixture')\n",
105100
"class TestMyStuff:\n",
@@ -258,7 +253,6 @@
258253
"metadata": {},
259254
"outputs": [],
260255
"source": [
261-
"# scope is function also by default\n",
262256
"@pytest.fixture(scope=\"function\")\n",
263257
"def func_fixture():\n",
264258
" print(\"\\nfunc\")\n",
@@ -373,7 +367,7 @@
373367
"name": "python",
374368
"nbconvert_exporter": "python",
375369
"pygments_lexer": "ipython3",
376-
"version": "3.10.3"
370+
"version": "3.11.0"
377371
}
378372
},
379373
"nbformat": 4,

0 commit comments

Comments
 (0)