summaryrefslogtreecommitdiff
path: root/tests/conftest.py
blob: 1beffc6ec86fa737d8435dd25156ab8a23223e62 (plain)
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
import os
import sys
from typing import Callable
import pytest
from logging import getLogger, DEBUG

from pyssg.arg_parser import get_parser
from pyssg.custom_logger import setup_logger


@pytest.fixture
def test_dir():
    return os.path.dirname(os.path.abspath(__file__))


@pytest.fixture(scope='session')
def arg_parser():
    return get_parser()


@pytest.fixture(scope='session')
def logger():
    setup_logger(__name__, DEBUG)
    return getLogger(__name__)


@pytest.fixture
def capture_stdout(monkeypatch: Callable) -> dict[str, str | int]:
    buffer: dict[str, str | int] = {'stdout': '', 'write_calls': 0}

    def fake_writer(s):
        buffer['stdout'] += s
        buffer['write_calls'] += 1  # type: ignore

    monkeypatch.setattr(sys.stdout, 'write', fake_writer)
    return buffer