File: conftest.py

package info (click to toggle)
mkdocs-section-index 0.3.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: python: 486; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 841 bytes parent folder | download | duplicates (2)
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
import functools
import http.server
import logging
import threading

import pytest
import testfixtures


@pytest.fixture(autouse=True)
def cap_log():
    with testfixtures.LogCapture(
        "mkdocs.plugins.mkdocs_section_index",
        attributes=("levelname", "getMessage"),
        ensure_checks_above=logging.WARNING,
    ) as capture:
        yield capture


@pytest.fixture(scope="session")
def http_server(tmp_path_factory):
    directory = tmp_path_factory.mktemp("http_server")
    httpd = http.server.HTTPServer(
        ("localhost", 0),
        functools.partial(http.server.SimpleHTTPRequestHandler, directory=str(directory)),
    )
    t = threading.Thread(target=httpd.serve_forever)
    t.daemon = True
    t.start()
    httpd.directory = directory
    httpd.url = f"http://localhost:{httpd.server_port}/"
    return httpd