1👍
✅
You should have the DEBUG
variable in your settings.py
and assume that you initialize this variable from .env
to determine if its production or not. Then you can initialize the TIMEOUT
variable in settings.py
depending on DEBUG
variable like this:
DEBUG = os.getenv("DEBUG") == "True"
TIMEOUT = 0.1 if DEBUG else 10
0👍
To fix this I did 2 things:
- I changed the way the module is loaded:
import request_maker
- I reloaded the module after I updated the settings
settings.TIMEOUT = 0.1
reload(request_maker)
Here is the full new code:
###############
tests.py
###############
import pytest
from timeout_decorator import TimeoutError
import request_maker
from importlib import reload
def test_make_request(settings):
settings.TIMEOUT = 0.1
reload(request_maker)
mr = request_maker.MakeRequest()
with pytest.raises(TimeoutError) as e:
mr.make_the_request() # < Sleeps for 0.1 seconds only!
- [Answered ]-Grouping django objects using QuerySet API by shared text tags using two models with ForeignKey relationship
- [Answered ]-Gunicorn – ModuleNotFoundError: No module named 'environ'
- [Answered ]-Django: provide month and year number as parameter in a template for use in template tag
- [Answered ]-Django: more complicated filter
Source:stackexchange.com