File: conftest.py

package info (click to toggle)
swagger-spec-validator 3.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 696 kB
  • sloc: python: 2,321; makefile: 28; sh: 2
file content (31 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (3)
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
import os

import pytest


def is_urlopen_error(exception):
    return any(
        urlopen_error_str in str(exception)
        for urlopen_error_str in {
            "<urlopen error [Errno -2] Name or service not known>",
            "<urlopen error [Errno -3] Temporary failure in name resolution>",
            "<urlopen error [Errno 8] nodename nor servname provided, or not known",
            "<urlopen error [Errno -5] No address associated with hostname>",
            "<urlopen error [Errno 11001] getaddrinfo failed>",
        }
    )


@pytest.fixture(autouse=True)
def change_dir():
    """
    Change the base directory to git root directory such that tests does not need to
    generate the absolute path for the data files.
    A relative path from git top-level directory will work as well
    """
    current_directory = os.path.abspath(os.curdir)
    try:
        os.chdir(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
        yield
    finally:
        os.chdir(current_directory)