Project

General

Profile

0001-tests-remove-some-handlers-added-by-pytest-45615.patch

Nicolas Roche, 31 Jul 2020 01:39 PM

Download (2.52 KB)

View differences:

Subject: [PATCH] tests: remove some handlers added by pytest (#45615)

 tests_multitenant/test_request_context_filter.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tests_multitenant/test_request_context_filter.py
16 16
        self.calls = []
17 17

  
18 18
    def send(self, *args, **kwargs):
19 19
        self.calls.append((args, kwargs))
20 20

  
21 21

  
22 22
def test_request_context_filter(caplog, settings, tenants, client):
23 23
    root_logger = logging.getLogger()
24
    assert len(root_logger.handlers) == 1
25
    root_logger.handlers[0].addFilter(RequestContextFilter())
24
    assert len(root_logger.handlers)
25
    root_logger.handlers[-1].addFilter(RequestContextFilter())
26 26
    for tenant in tenants:
27 27
        with tenant_context(tenant):
28 28
            user = User.objects.create(first_name='John', last_name='Doe', username='john.doe',
29 29
                                       email='jodn.doe@example.com')
30 30
            user.set_password('john.doe')
31 31
            user.save()
32 32
            user.saml_identifiers.create(name_id='ab' * 16, issuer='https://idp.example.com')
33 33

  
......
65 65
    root_logger.handlers.append(journald_handler)
66 66
    try:
67 67
        yield journald_handler
68 68
    finally:
69 69
        root_logger.handlers.remove(journald_handler)
70 70

  
71 71

  
72 72
def test_systemd(settings, tenants, client, journald_handler, sender):
73
    from _pytest.logging import LogCaptureHandler
74

  
73 75
    root_logger = logging.getLogger()
74
    assert len(root_logger.handlers) == 2
76
    assert len(root_logger.handlers)
77
    for idx, handler in enumerate(root_logger.handlers):
78
        if handler.__class__ == LogCaptureHandler and handler.filters \
79
           and handler.filters[0].__class__ == RequestContextFilter:
80
            del root_logger.handlers[idx]
75 81

  
76 82
    for tenant in tenants:
77 83
        with tenant_context(tenant):
78 84
            user = User.objects.create(first_name='John', last_name='Doe', username='john.doe',
79 85
                                       email='jodn.doe@example.com')
80 86
            user.set_password('john.doe')
81 87
            user.save()
82 88
            user.saml_identifiers.create(name_id='ab' * 16, issuer='https://idp.example.com')
83
-