File: conftest.py

package info (click to toggle)
jupyter-server 2.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,068 kB
  • sloc: python: 21,064; makefile: 186; sh: 25; javascript: 14
file content (34 lines) | stat: -rw-r--r-- 921 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
33
34
import os
import pathlib

import pytest

from jupyter_server import DEFAULT_JUPYTER_SERVER_PORT


@pytest.fixture
def jp_process_id():
    """Choose a random unused process ID."""
    return os.getpid()


@pytest.fixture
def jp_unix_socket_file(jp_process_id):
    """Define a temporary socket connection"""
    # Rely on `/tmp` to avoid any Linux socket length max buffer
    # issues. Key on PID for process-wise concurrency.
    tmp_path = pathlib.Path("/tmp")
    filename = f"jupyter_server.{jp_process_id}.sock"
    jp_unix_socket_file = tmp_path.joinpath(filename)
    yield str(jp_unix_socket_file)
    # Clean up the file after the test runs.
    if jp_unix_socket_file.exists():
        jp_unix_socket_file.unlink()


@pytest.fixture
def jp_http_port():
    """Set the port to the default value, since sock
    and port cannot both be configured at the same time.
    """
    return DEFAULT_JUPYTER_SERVER_PORT