File: test_zz_resources.py

package info (click to toggle)
python-scrapy 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,308 kB
  • sloc: python: 55,321; xml: 199; makefile: 25; sh: 7
file content (36 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Test that certain resources are not leaked during earlier tests."""

from __future__ import annotations

import asyncio
import logging

import pytest

from scrapy.utils.log import LogCounterHandler


def test_counter_handler() -> None:
    """Test that ``LogCounterHandler`` is always properly removed.

    It's added in ``Crawler.crawl{,_async}()`` and removed on engine_stopped.
    """
    c = sum(1 for h in logging.root.handlers if isinstance(h, LogCounterHandler))
    assert c == 0


def test_stderr_log_handler() -> None:
    """Test that the Scrapy root handler is always properly removed.

    It's added in ``configure_logging()``, called by ``{Async,}CrawlerProcess``
    (without ``install_root_handler=False``). It can be removed with
    ``_uninstall_scrapy_root_handler()`` if installing it was really neeeded.
    """
    c = sum(1 for h in logging.root.handlers if type(h) is logging.StreamHandler)  # pylint: disable=unidiomatic-typecheck
    assert c == 0


@pytest.mark.only_asyncio
def test_pending_asyncio_tasks() -> None:
    """Test that there are no pending asyncio tasks."""
    assert not asyncio.all_tasks()