From 44d09f4c76297d407d96c14cdc56858b9fdd63f6 Mon Sep 17 00:00:00 2001 From: Dario Cambie Date: Thu, 13 Jul 2023 13:58:24 +0200 Subject: [PATCH] fix pytest --- pyproject.toml | 1 + tests/conftest.py | 9 +-------- tests/server/test_server.py | 32 ++++---------------------------- 3 files changed, 6 insertions(+), 36 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e6e6aef5..1591baa0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,6 +53,7 @@ test = [ "pytest-asyncio", "pytest-cov", "pytest-mock", + "pytest-xprocess", "httpx", "requests", ] diff --git a/tests/conftest.py b/tests/conftest.py index 7014f053..b34db885 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,14 +9,7 @@ @pytest.fixture(scope="module") def flowchem_test_instance(xprocess): config_file = Path(__file__).parent.resolve() / "test_config.toml" - main = ( - Path(__file__).parent.resolve() - / ".." - / ".." - / "src" - / "flowchem" - / "__main__.py" - ) + main = Path(__file__).parent.resolve() / ".." / "src" / "flowchem" / "__main__.py" class Starter(ProcessStarter): # Process startup ends with this text in stdout diff --git a/tests/server/test_server.py b/tests/server/test_server.py index 82a39148..859751b0 100644 --- a/tests/server/test_server.py +++ b/tests/server/test_server.py @@ -1,38 +1,14 @@ -import asyncio -from pathlib import Path -from textwrap import dedent - -import pytest -from click.testing import CliRunner -from fastapi.testclient import TestClient - -from flowchem.server.create_server import create_server_from_file - - -@pytest.fixture(scope="function") -def app(): - runner = CliRunner() - with runner.isolated_filesystem(): - with open("test_configuration.toml", "w") as f: - f.write( - dedent( - """[device.test-device]\n - type = "FakeDevice"\n""" - ) - ) - server = asyncio.run(create_server_from_file(Path("test_configuration.toml"))) - yield server["api_server"].app +import requests def test_read_main(flowchem_test_instance): - client = TestClient(app) - response = client.get("/") + response = requests.get(r"http://127.0.0.1:8000/") assert response.status_code == 200 assert "Flowchem" in response.text - response = client.get("/test-device/test-component/test") + response = requests.get(r"http://127.0.0.1:8000/test-device/test-component/test") assert response.status_code == 200 assert response.text == "true" - response = client.get("/test-device2") + response = requests.get(r"http://127.0.0.1:8000/test-device2") assert response.status_code == 404