I'm trying to test max_execution_time option of mysql in Django with pytest. But I'm having trouble with making slow query to test the option with pytest. Can you give me any tips or good example of slow query?
Environment
- Python 3.8.10
- Django 3.0.14
- pytest 5.4.3
- MySQL 5.7
Tried
@pytest.mark.django_db
def test_max_execution_time():
with pytest.raise(OperationalError):
result = list(Blog.objects.raw("""
CREATE PROCEDURE InfLoop()
BEGIN
WHILE 1=1 DO
SELECT 1;
END WHILE;
END;
CALL InfLoop();
"""))
pytest test.py
Actual
FAILED test.py F
===================================================================================== FAILURES ======================================================================================
______________________________________________________________________ test_max_execution_time _______________________________________________________________________
@pytest.mark.django_db
def test_max_execution_time():
with pytest.raises(OperationalError):
> result = list(Blog.objects.raw("""
CREATE PROCEDURE InfLoop()
BEGIN
WHILE 1=1 DO
SELECT 1;
END WHILE;
END;
CALL InfLoop();
"""))
E Failed: DID NOT RAISE <class 'django.db.utils.OperationalError'>
test.py:102: Failed
============================================================================== short test summary info ==============================================================================
FAILED test.py::test_max_execution_time - Failed: DID NOT RAISE <class'django.db.utils.OperationalError'>
Expected
1 passed