Skip to content

--no-monitor breaks pytest.raises and django_assert_num_queries  #79

@Veritogen

Description

@Veritogen

Describe the bug
When we add --no-monitor to the pytest.ini like so addopts = --no-monitor, pytest.raises, django_assert_num_queries and django_assert_max_num_queries (the latter two are provided by pytest-django) do not work anymore. They should be raising test failures.

To Reproduce
Steps to reproduce the behavior:
0. (install django, pytest, pytetst-monitor and pytest-django)

  1. create a django project
  2. create an app
  3. create Book model in app
  4. run tests below with --no-monitor => all tests pass
  5. run tests below without --no-monitor => all tests fail
import pytest

from books.models import Book

def test_raise_exception():
    with pytest.raises(Exception):
        x = 1 / 1
        
def test_query_assertion(django_assert_num_queries, db):
    with django_assert_num_queries(0):
        print(Book.objects.all())

def test_max_queries_assertion(django_assert_max_num_queries, db):
    with django_assert_max_num_queries(0):
        print(Book.objects.all())

Expected behavior
The tests should fail, even though the --no-monitor flag was provided.

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • Python version: 3.11
  • Pytest version: 8.2.0
  • pytest-monitor version: 1.6.6

Additional context
Please ask if I missed to provide necessary information!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions