tests: Move fixtures to conftest.py, and use in all existing applicable tests

This commit is contained in:
Athanasius 2022-08-29 16:04:18 +01:00
parent bc5f7e9059
commit b4deb19e6e
No known key found for this signature in database
GPG Key ID: 8C392035DD80FD62
2 changed files with 24 additions and 26 deletions

View File

@ -1,4 +1,6 @@
"""General pytest configuration, including fixtures."""
import os
import sys
from typing import Callable, Optional
import pytest
@ -53,3 +55,25 @@ def eddn_message() -> Callable:
return test_messages.get(msg_type)
return _method
@pytest.fixture
def fix_sys_path() -> None:
"""Set up an eddn.Gateway import."""
# Tests don't include the directory that `pytest` is run from on sys.path
sys.path.append(os.getcwd())
@pytest.fixture(scope="session")
def eddn_gateway():
"""Set up an eddn.Gateway import."""
import eddn.Gateway
class CLArgs:
config = False
cl_args = CLArgs()
eddn.Gateway.load_config(cl_args)
eddn.Gateway.configure()
return eddn.Gateway

View File

@ -1,32 +1,6 @@
"""Tests for eddn.Gateway.parse_and_error_handle."""
import os
import sys
from typing import Callable
import pytest
@pytest.fixture
def fix_sys_path() -> None:
"""Set up an eddn.Gateway import."""
# Tests don't include the directory that `pytest` is run from on sys.path
sys.path.append(os.getcwd())
@pytest.fixture(scope='module')
def eddn_gateway():
"""Set up an eddn.Gateway import."""
import eddn.Gateway
class CLArgs:
config = False
cl_args = CLArgs()
eddn.Gateway.load_config(cl_args)
eddn.Gateway.configure()
return eddn.Gateway
def test_invalid_json(fix_sys_path, eddn_gateway, eddn_message: Callable) -> None:
"""Test invalid JSON input."""