Skip to content

Commit 91a53da

Browse files
enable pytest formatting with Ruff's PT (#234)
* enable pytes formating with Ruff's PT * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixing * Apply suggestions from code review * fixing --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d2a4aa4 commit 91a53da

6 files changed

Lines changed: 47 additions & 45 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ lint.extend-select = [
9292
"A", # see: https://pypi.org/project/flake8-builtins
9393
"B", # see: https://pypi.org/project/flake8-bugbear
9494
"C4", # see: https://pypi.org/project/flake8-comprehensions
95+
"PT", # see: https://pypi.org/project/flake8-pytest-style
9596
]
9697
lint.ignore = [
9798
"C901",

tests/test_defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def global_test_2():
6464
assert global_test_2.cache_dpath() is not None
6565

6666

67-
@pytest.mark.mongo
67+
@pytest.mark.mongo()
6868
def test_mongetter_default_param():
6969
cachier.set_default_params(mongetter=_test_mongetter)
7070

tests/test_general.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _calls_wait_for_calc_timeout_slow(res_queue):
154154

155155

156156
@pytest.mark.parametrize(
157-
"mongetter,backend",
157+
("mongetter", "backend"),
158158
[
159159
pytest.param(_test_mongetter, "mongo", marks=pytest.mark.mongo),
160160
(None, "memory"),
@@ -176,7 +176,7 @@ def dummy_func(arg_1, arg_2):
176176

177177

178178
@pytest.mark.parametrize(
179-
"mongetter,backend",
179+
("mongetter", "backend"),
180180
[
181181
pytest.param(_test_mongetter, "mongo", marks=pytest.mark.mongo),
182182
(None, "memory"),

tests/test_memory_core.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _takes_2_seconds(arg_1, arg_2):
1919
return f"arg_1:{arg_1}, arg_2:{arg_2}"
2020

2121

22-
@pytest.mark.memory
22+
@pytest.mark.memory()
2323
def test_memory_core():
2424
"""Basic memory core functionality."""
2525
_takes_2_seconds.clear_cache()
@@ -31,7 +31,7 @@ def test_memory_core():
3131
_takes_2_seconds.clear_cache()
3232

3333

34-
@pytest.mark.memory
34+
@pytest.mark.memory()
3535
def test_memory_core_keywords():
3636
"""Basic memory core functionality with keyword arguments."""
3737
_takes_2_seconds.clear_cache()
@@ -53,7 +53,7 @@ def _stale_after_seconds(arg_1, arg_2):
5353
return random()
5454

5555

56-
@pytest.mark.memory
56+
@pytest.mark.memory()
5757
def test_stale_after():
5858
"""Testing the stale_after functionality."""
5959
_stale_after_seconds.clear_cache()
@@ -74,7 +74,7 @@ def _stale_after_next_time(arg_1, arg_2):
7474
return random()
7575

7676

77-
@pytest.mark.memory
77+
@pytest.mark.memory()
7878
def test_stale_after_next_time():
7979
"""Testing the stale_after with next_time functionality."""
8080
_stale_after_next_time.clear_cache()
@@ -103,7 +103,7 @@ def _random_num_with_arg(a):
103103
return random()
104104

105105

106-
@pytest.mark.memory
106+
@pytest.mark.memory()
107107
def test_overwrite_cache():
108108
"""Tests that the overwrite feature works correctly."""
109109
_random_num.clear_cache()
@@ -127,7 +127,7 @@ def test_overwrite_cache():
127127
_random_num_with_arg.clear_cache()
128128

129129

130-
@pytest.mark.memory
130+
@pytest.mark.memory()
131131
def test_ignore_cache():
132132
"""Tests that the ignore_cache feature works correctly."""
133133
_random_num.clear_cache()
@@ -165,7 +165,7 @@ def _calls_takes_time(res_queue):
165165
res_queue.put(res)
166166

167167

168-
@pytest.mark.memory
168+
@pytest.mark.memory()
169169
def test_memory_being_calculated():
170170
"""Testing memory core handling of being calculated scenarios."""
171171
_takes_time.clear_cache()
@@ -199,7 +199,7 @@ def _calls_being_calc_next_time(res_queue):
199199
res_queue.put(res)
200200

201201

202-
@pytest.mark.memory
202+
@pytest.mark.memory()
203203
def test_being_calc_next_time():
204204
"""Testing memory core handling of being calculated scenarios."""
205205
_takes_time.clear_cache()
@@ -241,7 +241,7 @@ def _delete_cache(arg_1, arg_2):
241241
return random() + arg_1 + arg_2
242242

243243

244-
@pytest.mark.memory
244+
@pytest.mark.memory()
245245
def test_clear_being_calculated():
246246
"""Test memory core clear `being calculated` functionality."""
247247
_takes_time.clear_cache()
@@ -264,7 +264,7 @@ def test_clear_being_calculated():
264264
assert res1 != res2
265265

266266

267-
@pytest.mark.memory
267+
@pytest.mark.memory()
268268
def test_clear_being_calculated_with_empty_cache():
269269
"""Test memory core clear `being calculated` functionality."""
270270
_takes_time.clear_cache()
@@ -281,7 +281,7 @@ def _error_throwing_func(arg1):
281281
return 7
282282

283283

284-
@pytest.mark.memory
284+
@pytest.mark.memory()
285285
def test_error_throwing_func():
286286
# with
287287
res1 = _error_throwing_func(4)
@@ -290,7 +290,7 @@ def test_error_throwing_func():
290290
assert res1 == res2
291291

292292

293-
@pytest.mark.memory
293+
@pytest.mark.memory()
294294
def test_callable_hash_param():
295295
def _hash_func(args, kwargs):
296296
def _hash(obj):

tests/test_mongo_core.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ def _test_mongetter():
7777
# === Mongo core tests ===
7878

7979

80-
@pytest.mark.mongo
80+
@pytest.mark.mongo()
8181
def test_information():
8282
print("\npymongo version: ", end="")
8383
print(pymongo.__version__)
8484

8585

86-
@pytest.mark.mongo
86+
@pytest.mark.mongo()
8787
def test_mongo_index_creation():
8888
"""Basic Mongo core functionality."""
8989

@@ -100,7 +100,7 @@ def _test_mongo_caching(arg_1, arg_2):
100100
assert _MongoCore._INDEX_NAME in collection.index_information()
101101

102102

103-
@pytest.mark.mongo
103+
@pytest.mark.mongo()
104104
def test_mongo_core():
105105
"""Basic Mongo core functionality."""
106106

@@ -123,7 +123,7 @@ def _test_mongo_caching(arg_1, arg_2):
123123
assert val6 == val5
124124

125125

126-
@pytest.mark.mongo
126+
@pytest.mark.mongo()
127127
def test_mongo_core_keywords():
128128
"""Basic Mongo core functionality with keyword arguments."""
129129

@@ -150,7 +150,7 @@ def _test_mongo_caching(arg_1, arg_2):
150150
MONGO_DELTA_LONG = timedelta(seconds=10)
151151

152152

153-
@pytest.mark.mongo
153+
@pytest.mark.mongo()
154154
def test_mongo_stale_after():
155155
"""Testing MongoDB core stale_after functionality."""
156156

@@ -181,7 +181,7 @@ def _takes_time(arg_1, arg_2):
181181
res_queue.put(res)
182182

183183

184-
@pytest.mark.mongo
184+
@pytest.mark.mongo()
185185
def test_mongo_being_calculated():
186186
"""Testing MongoDB core handling of being calculated scenarios."""
187187

@@ -231,7 +231,7 @@ def _bad_mongetter():
231231
return _BadMongoCollection(_test_mongetter)
232232

233233

234-
@pytest.mark.mongo
234+
@pytest.mark.mongo()
235235
def test_mongo_write_failure():
236236
"""Testing MongoDB core handling of writing failure scenarios."""
237237

@@ -241,12 +241,13 @@ def _func_w_bad_mongo(arg_1, arg_2):
241241
return random() + arg_1 + arg_2
242242

243243
with pytest.raises(OperationFailure):
244-
val1 = _func_w_bad_mongo(1, 2)
245-
val2 = _func_w_bad_mongo(1, 2)
246-
assert val1 == val2
244+
_func_w_bad_mongo(1, 2)
245+
with pytest.raises(OperationFailure):
246+
_func_w_bad_mongo(1, 2)
247+
# assert val1 == val2
247248

248249

249-
@pytest.mark.mongo
250+
@pytest.mark.mongo()
250251
def test_mongo_clear_being_calculated():
251252
"""Testing MongoDB core clear_being_calculated."""
252253

@@ -258,7 +259,7 @@ def _func_w_bad_mongo(arg_1, arg_2):
258259
_func_w_bad_mongo.clear_being_calculated()
259260

260261

261-
@pytest.mark.mongo
262+
@pytest.mark.mongo()
262263
def test_stalled_mongo_db_cache():
263264
@cachier(mongetter=_test_mongetter)
264265
def _stalled_func():
@@ -271,7 +272,7 @@ def _stalled_func():
271272
core.wait_on_entry_calc(key=None)
272273

273274

274-
@pytest.mark.mongo
275+
@pytest.mark.mongo()
275276
def test_stalled_mong_db_core(monkeypatch):
276277
def mock_get_entry(self, args, kwargs):
277278
return "key", {"being_calculated": True}
@@ -327,7 +328,7 @@ def _stalled_func_3():
327328
assert res == 1
328329

329330

330-
@pytest.mark.mongo
331+
@pytest.mark.mongo()
331332
def test_callable_hash_param():
332333
def _hash_func(args, kwargs):
333334
def _hash(obj):

tests/test_pickle_core.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _takes_2_seconds(arg_1, arg_2):
4747
return f"arg_1:{arg_1}, arg_2:{arg_2}"
4848

4949

50-
@pytest.mark.pickle
50+
@pytest.mark.pickle()
5151
@pytest.mark.parametrize("reload", [True, False])
5252
@pytest.mark.parametrize("separate_files", [True, False])
5353
def test_pickle_core(reload, separate_files):
@@ -67,7 +67,7 @@ def test_pickle_core(reload, separate_files):
6767
_takes_2_seconds_decorated.clear_cache()
6868

6969

70-
@pytest.mark.pickle
70+
@pytest.mark.pickle()
7171
@pytest.mark.parametrize("separate_files", [True, False])
7272
def test_pickle_core_keywords(separate_files):
7373
"""Basic Pickle core functionality with keyword arguments."""
@@ -92,7 +92,7 @@ def _stale_after_seconds(arg_1, arg_2):
9292
return random()
9393

9494

95-
@pytest.mark.pickle
95+
@pytest.mark.pickle()
9696
@pytest.mark.parametrize("separate_files", [True, False])
9797
def test_stale_after(separate_files):
9898
"""Testing the stale_after functionality."""
@@ -119,7 +119,7 @@ def _stale_after_next_time(arg_1, arg_2):
119119
return random()
120120

121121

122-
@pytest.mark.pickle
122+
@pytest.mark.pickle()
123123
@pytest.mark.parametrize("separate_files", [True, False])
124124
def test_stale_after_next_time(separate_files):
125125
"""Testing the stale_after with next_time functionality."""
@@ -153,7 +153,7 @@ def _random_num_with_arg(a):
153153
return random()
154154

155155

156-
@pytest.mark.pickle
156+
@pytest.mark.pickle()
157157
@pytest.mark.parametrize("separate_files", [True, False])
158158
def test_overwrite_cache(separate_files):
159159
"""Tests that the overwrite feature works correctly."""
@@ -184,7 +184,7 @@ def test_overwrite_cache(separate_files):
184184
_random_num_with_arg_decorated.clear_cache()
185185

186186

187-
@pytest.mark.pickle
187+
@pytest.mark.pickle()
188188
@pytest.mark.parametrize("separate_files", [True, False])
189189
def test_ignore_cache(separate_files):
190190
"""Tests that the ignore_cache feature works correctly."""
@@ -228,7 +228,7 @@ def _calls_takes_time(takes_time_func, res_queue):
228228
res_queue.put(res)
229229

230230

231-
@pytest.mark.pickle
231+
@pytest.mark.pickle()
232232
@pytest.mark.parametrize("separate_files", [True, False])
233233
def test_pickle_being_calculated(separate_files):
234234
"""Testing pickle core handling of being calculated scenarios."""
@@ -275,7 +275,7 @@ def _calls_being_calc_next_time(being_calc_func, res_queue):
275275
res_queue.put(res)
276276

277277

278-
@pytest.mark.pickle
278+
@pytest.mark.pickle()
279279
@pytest.mark.parametrize("separate_files", [True, False])
280280
def test_being_calc_next_time(separate_files):
281281
"""Testing pickle core handling of being calculated scenarios."""
@@ -393,8 +393,8 @@ def _helper_bad_cache_file(sleeptime, separate_files):
393393

394394

395395
# we want this to succeed at least once
396-
@pytest.mark.pickle
397-
@pytest.mark.xfail
396+
@pytest.mark.pickle()
397+
@pytest.mark.xfail()
398398
@pytest.mark.parametrize("separate_files", [True, False])
399399
def test_bad_cache_file(separate_files):
400400
"""Test pickle core handling of bad cache files."""
@@ -484,8 +484,8 @@ def _helper_delete_cache_file(sleeptime, separate_files):
484484
return isinstance(res2, KeyError) or (res2 is None)
485485

486486

487-
@pytest.mark.pickle
488-
@pytest.mark.xfail
487+
@pytest.mark.pickle()
488+
@pytest.mark.xfail()
489489
@pytest.mark.parametrize("separate_files", [False, True])
490490
def test_delete_cache_file(separate_files):
491491
"""Test pickle core handling of missing cache files."""
@@ -497,7 +497,7 @@ def test_delete_cache_file(separate_files):
497497
raise AssertionError()
498498

499499

500-
@pytest.mark.pickle
500+
@pytest.mark.pickle()
501501
@pytest.mark.parametrize("separate_files", [False, True])
502502
def test_clear_being_calculated(separate_files):
503503
"""Test pickle core clear `being calculated` functionality."""
@@ -516,7 +516,7 @@ def _error_throwing_func(arg1):
516516
return 7
517517

518518

519-
@pytest.mark.pickle
519+
@pytest.mark.pickle()
520520
@pytest.mark.parametrize("separate_files", [True, False])
521521
def test_error_throwing_func(separate_files):
522522
# with
@@ -546,7 +546,7 @@ def _takes_2_seconds_custom_dir(arg_1, arg_2):
546546
return f"arg_1:{arg_1}, arg_2:{arg_2}"
547547

548548

549-
@pytest.mark.pickle
549+
@pytest.mark.pickle()
550550
@pytest.mark.parametrize("separate_files", [True, False])
551551
def test_pickle_core_custom_cache_dir(separate_files):
552552
"""Basic Pickle core functionality."""
@@ -567,7 +567,7 @@ def test_pickle_core_custom_cache_dir(separate_files):
567567
assert path2test == EXPANDED_CUSTOM_DIR
568568

569569

570-
@pytest.mark.pickle
570+
@pytest.mark.pickle()
571571
@pytest.mark.parametrize("separate_files", [True, False])
572572
def test_callable_hash_param(separate_files):
573573
def _hash_func(args, kwargs):

0 commit comments

Comments
 (0)