Skip to content

Commit

Permalink
use pytest.param instead of copy whole test (#145) (#147)
Browse files Browse the repository at this point in the history
use `pytest.param` instead of copy whole test
Authored-by: Jirka Borovec <[email protected]>, just merged by Shay Palachy Affek
  • Loading branch information
shaypal5 authored Feb 2, 2024
1 parent d19b3cf commit 9a68b3a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 49 deletions.
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ markers =
memory: test the memory core
pickle: test the pickle core
addopts =
--color=yes
# --doctest-modules
--cov=cachier
--cov-report term
Expand Down
6 changes: 2 additions & 4 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def _calls_wait_for_calc_timeout_slow(res_queue):
@pytest.mark.parametrize(
'mongetter,backend',
[
# (_test_mongetter, 'mongo'), # Please do NOT test the mongo backend
# here. It is tested in test_mongo_core.py
pytest.param(_test_mongetter, 'mongo', marks=pytest.mark.mongo),
(None, 'memory'),
(None, 'pickle'),
]
Expand Down Expand Up @@ -183,8 +182,7 @@ def func(arg_1, arg_2):
@pytest.mark.parametrize(
'mongetter,backend',
[
# (_test_mongetter, 'mongo'), # Please do NOT test the mongo backend
# here. It is tested in test_mongo_core.py
pytest.param(_test_mongetter, 'mongo', marks=pytest.mark.mongo),
(None, 'memory'),
(None, 'pickle'),
]
Expand Down
46 changes: 1 addition & 45 deletions tests/test_mongo_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import threading
from datetime import timedelta
from random import random
from time import sleep, time
from time import sleep
from urllib.parse import quote_plus

from birch import Birch # type: ignore[import-not-found]
Expand Down Expand Up @@ -120,50 +120,6 @@ def _test_mongo_caching(arg_1, arg_2):
assert val6 == val5


@pytest.mark.mongo
def test_mongo_precache_value():

@cachier(backend='mongo', mongetter=_test_mongetter)
def func(arg_1, arg_2):
"""Some function."""
return arg_1 + arg_2

result = func.precache_value(2, 2, value_to_cache=5)
assert result == 5
result = func(2, 2)
assert result == 5
func.clear_cache()
result = func(2, 2)
assert result == 4
result = func.precache_value(2, arg_2=2, value_to_cache=5)
assert result == 5
result = func(2, arg_2=2)
assert result == 5


@pytest.mark.mongo
def test_mongo_ignore_self_in_methods():

class TestClass():
@cachier(backend='mongo', mongetter=_test_mongetter)
def takes_2_seconds(self, arg_1, arg_2):
"""Some function."""
sleep(2)
return arg_1 + arg_2

test_object_1 = TestClass()
test_object_2 = TestClass()
test_object_1.takes_2_seconds.clear_cache()
test_object_2.takes_2_seconds.clear_cache()
result_1 = test_object_1.takes_2_seconds(1, 2)
assert result_1 == 3
start = time()
result_2 = test_object_2.takes_2_seconds(1, 2)
end = time()
assert result_2 == 3
assert end - start < 1


@pytest.mark.mongo
def test_mongo_core_keywords():
"""Basic Mongo core functionality with keyword arguments."""
Expand Down

0 comments on commit 9a68b3a

Please sign in to comment.