From d1c8f33fc59a31b31ec906ea229be2ccbc4cf3a5 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sat, 27 Aug 2022 19:16:02 +0200 Subject: [PATCH] Upgrade dev dependencies and fix issues after upgrading to pytest-aiohttp v1.0.4 --- dev-requirements.txt | 8 ++++---- gns3server/web/route.py | 2 +- tests/compute/builtin/nodes/test_cloud.py | 11 ++++++----- tests/compute/docker/test_docker.py | 5 +++-- tests/compute/docker/test_docker_vm.py | 4 ++-- tests/compute/dynamips/test_dynamips_manager.py | 5 +++-- tests/compute/dynamips/test_dynamips_router.py | 6 +++--- tests/compute/iou/test_iou_vm.py | 7 ++++--- tests/compute/qemu/test_qcow2.py | 2 +- tests/compute/qemu/test_qemu_vm.py | 5 +++-- tests/compute/test_base_node.py | 6 +++--- tests/compute/test_manager.py | 4 ++-- tests/compute/test_project.py | 2 +- tests/compute/traceng/test_traceng_vm.py | 7 ++++--- tests/compute/virtualbox/test_virtualbox_manager.py | 5 +++-- tests/compute/virtualbox/test_virtualbox_vm.py | 5 +++-- tests/compute/vmware/test_vmware_manager.py | 6 +++--- tests/compute/vmware/test_vmware_vm.py | 4 ++-- tests/compute/vpcs/test_vpcs_vm.py | 7 ++++--- tests/conftest.py | 7 ++++--- tests/controller/gns3vm/test_remote_gns3_vm.py | 2 +- tests/controller/gns3vm/test_virtualbox_gns3_vm.py | 7 +++---- tests/controller/gns3vm/test_vmware_gns3_vm.py | 5 +++-- tests/controller/test_export_project.py | 7 ++++--- tests/controller/test_gns3vm.py | 6 +++--- tests/controller/test_import_project.py | 12 ++++++------ tests/controller/test_link.py | 3 ++- tests/controller/test_notification.py | 4 ++-- tests/controller/test_project.py | 3 ++- tests/handlers/api/compute/test_docker.py | 3 ++- tests/handlers/api/compute/test_iou.py | 3 ++- tests/handlers/api/compute/test_qemu.py | 3 ++- tests/handlers/api/compute/test_vpcs.py | 4 ++-- tests/handlers/api/controller/test_link.py | 4 ++-- tests/handlers/api/controller/test_project.py | 3 ++- tests/handlers/api/controller/test_snapshot.py | 6 +++--- tests/pytest.ini | 2 ++ tests/test_config.py | 8 ++++---- tests/utils/test_asyncio.py | 2 +- tests/web/test_response.py | 2 +- 40 files changed, 108 insertions(+), 89 deletions(-) create mode 100644 tests/pytest.ini diff --git a/dev-requirements.txt b/dev-requirements.txt index eba5db79..6502bfec 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,6 +1,6 @@ -rrequirements.txt -pytest==7.0.0 -flake8==4.0.1 -pytest-timeout==1.4.2 -pytest-aiohttp==0.3.0 +pytest==7.1.2 +flake8==5.0.4 +pytest-timeout==2.1.0 +pytest-aiohttp==1.0.4 diff --git a/gns3server/web/route.py b/gns3server/web/route.py index d1275250..e788a32c 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -147,7 +147,7 @@ class Route(object): else: route = path - # Compute metadata for the documentation + # Compute metadata for the documentation if api_version: handler = func.__module__.replace("_handler", "").replace("gns3server.handlers.api.", "") cls._documentation.setdefault(handler, {}) diff --git a/tests/compute/builtin/nodes/test_cloud.py b/tests/compute/builtin/nodes/test_cloud.py index 3e5e5113..7cafef31 100644 --- a/tests/compute/builtin/nodes/test_cloud.py +++ b/tests/compute/builtin/nodes/test_cloud.py @@ -17,6 +17,7 @@ import uuid import pytest +import pytest_asyncio from unittest.mock import MagicMock, patch, call from gns3server.compute.builtin.nodes.cloud import Cloud @@ -30,8 +31,8 @@ def nio(): return NIOUDP(4242, "127.0.0.1", 4343) -@pytest.fixture -async def manager(loop): +@pytest_asyncio.fixture +async def manager(): m = MagicMock() m.module_name = "builtins" @@ -113,7 +114,7 @@ def test_json_without_ports(on_gns3vm, compute_project, manager): } -async def test_update_port_mappings(loop, on_gns3vm, compute_project): +async def test_update_port_mappings(on_gns3vm, compute_project): """ We don't allow an empty interface in the middle of port list """ @@ -153,7 +154,7 @@ async def test_update_port_mappings(loop, on_gns3vm, compute_project): assert cloud.ports_mapping == ports1 -async def test_linux_ethernet_raw_add_nio(loop, linux_platform, compute_project, nio): +async def test_linux_ethernet_raw_add_nio(linux_platform, compute_project, nio): ports = [ { "interface": "eth0", @@ -180,7 +181,7 @@ async def test_linux_ethernet_raw_add_nio(loop, linux_platform, compute_project, ]) -async def test_linux_ethernet_raw_add_nio_bridge(loop, linux_platform, compute_project, nio): +async def test_linux_ethernet_raw_add_nio_bridge(linux_platform, compute_project, nio): """ Bridge can't be connected directly to a cloud we use a tap in the middle """ diff --git a/tests/compute/docker/test_docker.py b/tests/compute/docker/test_docker.py index 2e9193ad..94a2d941 100644 --- a/tests/compute/docker/test_docker.py +++ b/tests/compute/docker/test_docker.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio from unittest.mock import MagicMock, patch from tests.utils import asyncio_patch, AsyncioMagicMock @@ -23,8 +24,8 @@ from gns3server.compute.docker import Docker, DOCKER_PREFERRED_API_VERSION, DOCK from gns3server.compute.docker.docker_error import DockerError, DockerHttp404Error -@pytest.fixture -async def vm(loop): +@pytest_asyncio.fixture +async def vm(): vm = Docker() vm._connected = True diff --git a/tests/compute/docker/test_docker_vm.py b/tests/compute/docker/test_docker_vm.py index 1effa9b0..15073cc6 100644 --- a/tests/compute/docker/test_docker_vm.py +++ b/tests/compute/docker/test_docker_vm.py @@ -34,7 +34,7 @@ from unittest.mock import patch, MagicMock, call @pytest.fixture() -async def manager(loop, port_manager): +async def manager(port_manager): m = Docker.instance() m.port_manager = port_manager @@ -42,7 +42,7 @@ async def manager(loop, port_manager): @pytest.fixture(scope="function") -async def vm(loop, compute_project, manager): +async def vm(compute_project, manager): vm = DockerVM("test", str(uuid.uuid4()), compute_project, manager, "ubuntu:latest") vm._cid = "e90e34656842" diff --git a/tests/compute/dynamips/test_dynamips_manager.py b/tests/compute/dynamips/test_dynamips_manager.py index aee2c326..e1b8585f 100644 --- a/tests/compute/dynamips/test_dynamips_manager.py +++ b/tests/compute/dynamips/test_dynamips_manager.py @@ -17,6 +17,7 @@ import pytest +import pytest_asyncio import tempfile import sys import uuid @@ -28,8 +29,8 @@ from unittest.mock import patch from tests.utils import asyncio_patch, AsyncioMagicMock -@pytest.fixture -async def manager(loop, port_manager): +@pytest_asyncio.fixture +async def manager(port_manager): m = Dynamips.instance() m.port_manager = port_manager diff --git a/tests/compute/dynamips/test_dynamips_router.py b/tests/compute/dynamips/test_dynamips_router.py index 3ab250a1..6aa5f33a 100644 --- a/tests/compute/dynamips/test_dynamips_router.py +++ b/tests/compute/dynamips/test_dynamips_router.py @@ -18,7 +18,7 @@ import os import uuid import pytest -import asyncio +import pytest_asyncio from gns3server.compute.dynamips.nodes.router import Router from gns3server.compute.dynamips.dynamips_error import DynamipsError @@ -26,8 +26,8 @@ from gns3server.compute.dynamips import Dynamips from gns3server.config import Config -@pytest.fixture -async def manager(loop, port_manager): +@pytest_asyncio.fixture +async def manager(port_manager): m = Dynamips.instance() m.port_manager = port_manager diff --git a/tests/compute/iou/test_iou_vm.py b/tests/compute/iou/test_iou_vm.py index 93fbb78d..d5fe9912 100644 --- a/tests/compute/iou/test_iou_vm.py +++ b/tests/compute/iou/test_iou_vm.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio import asyncio import os import stat @@ -36,8 +37,8 @@ if not sys.platform.startswith("win"): from gns3server.compute.iou import IOU -@pytest.fixture -async def manager(loop, port_manager): +@pytest_asyncio.fixture +async def manager(port_manager): m = IOU.instance() m.port_manager = port_manager @@ -45,7 +46,7 @@ async def manager(loop, port_manager): @pytest.fixture(scope="function") -async def vm(loop, compute_project, manager, tmpdir, fake_iou_bin, iourc_file): +async def vm(compute_project, manager, tmpdir, fake_iou_bin, iourc_file): vm = IOUVM("test", str(uuid.uuid4()), compute_project, manager, application_id=1) config = manager.config.get_section_config("IOU") diff --git a/tests/compute/qemu/test_qcow2.py b/tests/compute/qemu/test_qcow2.py index d185135b..b14e631e 100644 --- a/tests/compute/qemu/test_qcow2.py +++ b/tests/compute/qemu/test_qcow2.py @@ -66,7 +66,7 @@ def test_invalid_empty_file(tmpdir): @pytest.mark.skipif(qemu_img() is None, reason="qemu-img is not available") -async def test_rebase(loop, tmpdir): +async def test_rebase(tmpdir): shutil.copy("tests/resources/empty8G.qcow2", str(tmpdir / "empty16G.qcow2")) shutil.copy("tests/resources/linked.qcow2", str(tmpdir / "linked.qcow2")) diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 6b87a86b..bd7fa873 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio import asyncio import os import sys @@ -33,8 +34,8 @@ from gns3server.utils import force_unix_path, macaddress_to_int, int_to_macaddre from gns3server.compute.notification_manager import NotificationManager -@pytest.fixture -async def manager(loop, port_manager): +@pytest_asyncio.fixture +async def manager(port_manager): m = Qemu.instance() m.port_manager = port_manager diff --git a/tests/compute/test_base_node.py b/tests/compute/test_base_node.py index 9052a818..dab1a17c 100644 --- a/tests/compute/test_base_node.py +++ b/tests/compute/test_base_node.py @@ -18,7 +18,7 @@ from collections import OrderedDict import pytest -import asyncio +import pytest_asyncio from tests.utils import asyncio_patch, AsyncioMagicMock @@ -29,8 +29,8 @@ from gns3server.compute.vpcs import VPCS from gns3server.compute.nios.nio_udp import NIOUDP -@pytest.fixture(scope="function") -async def manager(loop, port_manager): +@pytest_asyncio.fixture(scope="function") +async def manager(port_manager): m = VPCS.instance() m.port_manager = port_manager diff --git a/tests/compute/test_manager.py b/tests/compute/test_manager.py index eef0d1d2..556072db 100644 --- a/tests/compute/test_manager.py +++ b/tests/compute/test_manager.py @@ -29,7 +29,7 @@ from gns3server.utils import force_unix_path @pytest.fixture(scope="function") -async def vpcs(loop, port_manager): +async def vpcs(port_manager): VPCS._instance = None vpcs = VPCS.instance() @@ -38,7 +38,7 @@ async def vpcs(loop, port_manager): @pytest.fixture(scope="function") -async def qemu(loop, port_manager): +async def qemu(port_manager): Qemu._instance = None Qemu._init_config_disk = MagicMock() # do not create the config.img image diff --git a/tests/compute/test_project.py b/tests/compute/test_project.py index 6ae23717..11870b62 100644 --- a/tests/compute/test_project.py +++ b/tests/compute/test_project.py @@ -33,7 +33,7 @@ from gns3server.config import Config @pytest.fixture(scope="function") -async def manager(loop, port_manager): +async def manager(port_manager): m = VPCS.instance() m.port_manager = port_manager diff --git a/tests/compute/traceng/test_traceng_vm.py b/tests/compute/traceng/test_traceng_vm.py index e4d381dd..84604976 100644 --- a/tests/compute/traceng/test_traceng_vm.py +++ b/tests/compute/traceng/test_traceng_vm.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio import asyncio from tests.utils import asyncio_patch, AsyncioMagicMock @@ -27,15 +28,15 @@ from gns3server.compute.traceng import TraceNG from gns3server.compute.notification_manager import NotificationManager -@pytest.fixture -async def manager(loop, port_manager): +@pytest_asyncio.fixture +async def manager(port_manager): m = TraceNG.instance() m.port_manager = port_manager return m -@pytest.fixture(scope="function") +@pytest_asyncio.fixture(scope="function") async def vm(compute_project, manager, ubridge_path): vm = TraceNGVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager) diff --git a/tests/compute/virtualbox/test_virtualbox_manager.py b/tests/compute/virtualbox/test_virtualbox_manager.py index 3ba1d9eb..4cc00971 100644 --- a/tests/compute/virtualbox/test_virtualbox_manager.py +++ b/tests/compute/virtualbox/test_virtualbox_manager.py @@ -17,6 +17,7 @@ import pytest +import pytest_asyncio import tempfile import os import stat @@ -28,8 +29,8 @@ from gns3server.compute.virtualbox.virtualbox_error import VirtualBoxError from tests.utils import asyncio_patch -@pytest.fixture -async def manager(loop, port_manager): +@pytest_asyncio.fixture +async def manager(port_manager): m = VirtualBox.instance() m.port_manager = port_manager diff --git a/tests/compute/virtualbox/test_virtualbox_vm.py b/tests/compute/virtualbox/test_virtualbox_vm.py index 12d59656..03ebd223 100644 --- a/tests/compute/virtualbox/test_virtualbox_vm.py +++ b/tests/compute/virtualbox/test_virtualbox_vm.py @@ -17,6 +17,7 @@ import os import pytest +import pytest_asyncio from tests.utils import asyncio_patch, AsyncioMagicMock from gns3server.compute.virtualbox.virtualbox_vm import VirtualBoxVM @@ -24,8 +25,8 @@ from gns3server.compute.virtualbox.virtualbox_error import VirtualBoxError from gns3server.compute.virtualbox import VirtualBox -@pytest.fixture -async def manager(loop, port_manager): +@pytest_asyncio.fixture +async def manager(port_manager): m = VirtualBox.instance() m.port_manager = port_manager diff --git a/tests/compute/vmware/test_vmware_manager.py b/tests/compute/vmware/test_vmware_manager.py index a26dbed1..7f2c2e0b 100644 --- a/tests/compute/vmware/test_vmware_manager.py +++ b/tests/compute/vmware/test_vmware_manager.py @@ -16,13 +16,13 @@ # along with this program. If not, see . -import pytest +import pytest_asyncio from gns3server.compute.vmware import VMware -@pytest.fixture -async def manager(loop, port_manager): +@pytest_asyncio.fixture +async def manager(port_manager): m = VMware.instance() m.port_manager = port_manager diff --git a/tests/compute/vmware/test_vmware_vm.py b/tests/compute/vmware/test_vmware_vm.py index 22bf1d46..bcfbefaa 100644 --- a/tests/compute/vmware/test_vmware_vm.py +++ b/tests/compute/vmware/test_vmware_vm.py @@ -16,14 +16,14 @@ # along with this program. If not, see . import pytest -import asyncio +import pytest_asyncio from gns3server.compute.vmware.vmware_vm import VMwareVM from gns3server.compute.vmware import VMware @pytest.fixture -async def manager(loop, port_manager): +async def manager(port_manager): m = VMware.instance() m.port_manager = port_manager diff --git a/tests/compute/vpcs/test_vpcs_vm.py b/tests/compute/vpcs/test_vpcs_vm.py index 618cabea..eda0c299 100644 --- a/tests/compute/vpcs/test_vpcs_vm.py +++ b/tests/compute/vpcs/test_vpcs_vm.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio import asyncio import os import sys @@ -30,8 +31,8 @@ from gns3server.compute.vpcs import VPCS from gns3server.compute.notification_manager import NotificationManager -@pytest.fixture -async def manager(loop, port_manager): +@pytest_asyncio.fixture +async def manager(port_manager): m = VPCS.instance() m.port_manager = port_manager @@ -39,7 +40,7 @@ async def manager(loop, port_manager): @pytest.fixture(scope="function") -async def vm(loop, compute_project, manager, tmpdir, ubridge_path): +async def vm(compute_project, manager, tmpdir, ubridge_path): vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager) vm._vpcs_version = parse_version("0.9") diff --git a/tests/conftest.py b/tests/conftest.py index 7311b7e6..b04309d2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import pytest +import pytest_asyncio import asyncio import tempfile import shutil @@ -34,7 +35,7 @@ if sys.platform.startswith("win"): asyncio.set_event_loop(None) -@pytest.fixture(scope='function') +@pytest_asyncio.fixture(scope='function') async def http_client(aiohttp_client): app = web.Application() @@ -71,8 +72,8 @@ def compute(controller): return compute -@pytest.fixture -async def project(loop, tmpdir, controller): +@pytest_asyncio.fixture +async def project(tmpdir, controller): return await controller.add_project(name="Test") diff --git a/tests/controller/gns3vm/test_remote_gns3_vm.py b/tests/controller/gns3vm/test_remote_gns3_vm.py index 1d1fc62f..09994b86 100644 --- a/tests/controller/gns3vm/test_remote_gns3_vm.py +++ b/tests/controller/gns3vm/test_remote_gns3_vm.py @@ -55,7 +55,7 @@ async def test_start(gns3vm, controller): assert gns3vm.password == "world" -async def test_start_invalid_vm(loop, gns3vm, controller): +async def test_start_invalid_vm(gns3vm, controller): await controller.add_compute("r1", name="R1", diff --git a/tests/controller/gns3vm/test_virtualbox_gns3_vm.py b/tests/controller/gns3vm/test_virtualbox_gns3_vm.py index eb90dce0..ff899c5b 100644 --- a/tests/controller/gns3vm/test_virtualbox_gns3_vm.py +++ b/tests/controller/gns3vm/test_virtualbox_gns3_vm.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import pytest -import asyncio +import pytest_asyncio from tests.utils import asyncio_patch, AsyncioMagicMock from gns3server.utils.asyncio import wait_run_in_executor @@ -25,8 +24,8 @@ from unittest.mock import patch from gns3server.controller.gns3vm.virtualbox_gns3_vm import VirtualBoxGNS3VM -@pytest.fixture -async def gns3vm(loop, controller): +@pytest_asyncio.fixture +async def gns3vm(controller): vm = VirtualBoxGNS3VM(controller) vm.vmname = "GNS3 VM" diff --git a/tests/controller/gns3vm/test_vmware_gns3_vm.py b/tests/controller/gns3vm/test_vmware_gns3_vm.py index cb0d54ad..bf48f199 100644 --- a/tests/controller/gns3vm/test_vmware_gns3_vm.py +++ b/tests/controller/gns3vm/test_vmware_gns3_vm.py @@ -16,12 +16,13 @@ # along with this program. If not, see . import pytest +import pytest_asyncio from gns3server.controller.gns3vm.vmware_gns3_vm import VMwareGNS3VM -@pytest.fixture -async def gns3vm(loop, controller): +@pytest_asyncio.fixture +async def gns3vm(controller): vm = VMwareGNS3VM(controller) vm.vmname = "GNS3 VM" diff --git a/tests/controller/test_export_project.py b/tests/controller/test_export_project.py index 973ed36e..02877bda 100644 --- a/tests/controller/test_export_project.py +++ b/tests/controller/test_export_project.py @@ -19,6 +19,7 @@ import os import json import pytest +import pytest_asyncio import aiohttp import zipfile @@ -32,15 +33,15 @@ from gns3server.controller.export_project import export_project, _is_exportable from gns3server.utils.asyncio import aiozipstream -@pytest.fixture -async def project(loop, controller): +@pytest_asyncio.fixture +async def project(controller): p = Project(controller=controller, name="test") p.dump = MagicMock() return p -@pytest.fixture +@pytest_asyncio.fixture async def node(controller, project): compute = MagicMock() diff --git a/tests/controller/test_gns3vm.py b/tests/controller/test_gns3vm.py index 8d01fae9..0058ed4c 100644 --- a/tests/controller/test_gns3vm.py +++ b/tests/controller/test_gns3vm.py @@ -47,7 +47,7 @@ def dummy_gns3vm(controller, dummy_engine): return vm -async def test_list(loop, controller): +async def test_list(controller): vm = GNS3VM(controller) with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.list", return_value=[{"vmname": "test", "vmx_path": "test"}]): @@ -60,14 +60,14 @@ async def test_list(loop, controller): await vm.list("hyperv") -async def test_json(loop, controller): +async def test_json(controller): vm = GNS3VM(controller) assert vm.__json__() == vm._settings @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not working well on Windows") -async def test_update_settings(loop, controller): +async def test_update_settings(controller): vm = GNS3VM(controller) vm.settings = { diff --git a/tests/controller/test_import_project.py b/tests/controller/test_import_project.py index 1ef9a2d5..e80da797 100644 --- a/tests/controller/test_import_project.py +++ b/tests/controller/test_import_project.py @@ -166,7 +166,7 @@ async def test_import_with_images(tmpdir, controller): assert os.path.exists(path), path -async def test_import_iou_linux_no_vm(loop, linux_platform, tmpdir, controller): +async def test_import_iou_linux_no_vm(linux_platform, tmpdir, controller): """ On non linux host IOU should be local if we don't have a GNS3 VM """ @@ -210,7 +210,7 @@ async def test_import_iou_linux_no_vm(loop, linux_platform, tmpdir, controller): assert topo["topology"]["nodes"][0]["compute_id"] == "local" -async def test_import_iou_linux_with_vm(loop, linux_platform, tmpdir, controller): +async def test_import_iou_linux_with_vm(linux_platform, tmpdir, controller): """ On non linux host IOU should be vm if we have a GNS3 VM configured """ @@ -255,7 +255,7 @@ async def test_import_iou_linux_with_vm(loop, linux_platform, tmpdir, controller assert topo["topology"]["nodes"][0]["compute_id"] == "vm" -async def test_import_nat_non_linux(loop, windows_platform, tmpdir, controller): +async def test_import_nat_non_linux(windows_platform, tmpdir, controller): """ On non linux host NAT should be moved to the GNS3 VM """ @@ -300,7 +300,7 @@ async def test_import_nat_non_linux(loop, windows_platform, tmpdir, controller): assert topo["topology"]["nodes"][0]["compute_id"] == "vm" -async def test_import_iou_non_linux(loop, windows_platform, tmpdir, controller): +async def test_import_iou_non_linux(windows_platform, tmpdir, controller): """ On non linux host IOU should be moved to the GNS3 VM """ @@ -356,7 +356,7 @@ async def test_import_iou_non_linux(loop, windows_platform, tmpdir, controller): mock.assert_called_with(controller._computes["vm"], project_id, project.path, os.path.join('project-files', 'iou', topo["topology"]["nodes"][0]['node_id'])) -async def test_import_node_id(loop, linux_platform, tmpdir, controller): +async def test_import_node_id(linux_platform, tmpdir, controller): """ When importing a node, node_id should change """ @@ -449,7 +449,7 @@ async def test_import_node_id(loop, linux_platform, tmpdir, controller): assert os.path.exists(os.path.join(project.path, "project-files", "iou", topo["topology"]["nodes"][0]["node_id"], "startup.cfg")) -async def test_import_keep_compute_id(loop, windows_platform, tmpdir, controller): +async def test_import_keep_compute_id(windows_platform, tmpdir, controller): """ On linux host IOU should be moved to the GNS3 VM """ diff --git a/tests/controller/test_link.py b/tests/controller/test_link.py index 702dbdc2..25a82404 100644 --- a/tests/controller/test_link.py +++ b/tests/controller/test_link.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio import aiohttp from unittest.mock import MagicMock @@ -26,7 +27,7 @@ from gns3server.controller.ports.serial_port import SerialPort from tests.utils import AsyncioBytesIO, AsyncioMagicMock -@pytest.fixture +@pytest_asyncio.fixture async def link(project, compute): node1 = Node(project, compute, "node1", node_type="qemu") diff --git a/tests/controller/test_notification.py b/tests/controller/test_notification.py index d0cc4e3d..ab2c0f39 100644 --- a/tests/controller/test_notification.py +++ b/tests/controller/test_notification.py @@ -15,13 +15,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import pytest +import pytest_asyncio from unittest.mock import MagicMock from tests.utils import AsyncioMagicMock -@pytest.fixture +@pytest_asyncio.fixture async def node(project): compute = MagicMock() diff --git a/tests/controller/test_project.py b/tests/controller/test_project.py index bc729fee..48c8a758 100644 --- a/tests/controller/test_project.py +++ b/tests/controller/test_project.py @@ -20,6 +20,7 @@ import os import sys import uuid import pytest +import pytest_asyncio import aiohttp from unittest.mock import MagicMock from tests.utils import AsyncioMagicMock, asyncio_patch @@ -33,7 +34,7 @@ from gns3server.controller.ports.ethernet_port import EthernetPort from gns3server.config import Config -@pytest.fixture +@pytest_asyncio.fixture async def node(controller, project): compute = MagicMock() diff --git a/tests/handlers/api/compute/test_docker.py b/tests/handlers/api/compute/test_docker.py index 217fb3b0..878c99c0 100644 --- a/tests/handlers/api/compute/test_docker.py +++ b/tests/handlers/api/compute/test_docker.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio import sys import uuid @@ -52,7 +53,7 @@ def base_params(): # Docker._instance = None -@pytest.fixture +@pytest_asyncio.fixture async def vm(compute_api, compute_project, base_params): with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "nginx"}]): diff --git a/tests/handlers/api/compute/test_iou.py b/tests/handlers/api/compute/test_iou.py index aadb4fa0..f54c926b 100644 --- a/tests/handlers/api/compute/test_iou.py +++ b/tests/handlers/api/compute/test_iou.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio import os import stat import sys @@ -45,7 +46,7 @@ def base_params(tmpdir, fake_iou_bin): return {"application_id": 42, "name": "PC TEST 1", "path": "iou.bin"} -@pytest.fixture +@pytest_asyncio.fixture async def vm(compute_api, compute_project, base_params): response = await compute_api.post("/projects/{project_id}/iou/nodes".format(project_id=compute_project.id), base_params) diff --git a/tests/handlers/api/compute/test_qemu.py b/tests/handlers/api/compute/test_qemu.py index 00245f25..7575a0b4 100644 --- a/tests/handlers/api/compute/test_qemu.py +++ b/tests/handlers/api/compute/test_qemu.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import pytest_asyncio import uuid import os import sys @@ -57,7 +58,7 @@ def base_params(tmpdir, fake_qemu_bin): return {"name": "PC TEST 1", "qemu_path": fake_qemu_bin} -@pytest.fixture +@pytest_asyncio.fixture async def vm(compute_api, compute_project, base_params): response = await compute_api.post("/projects/{project_id}/qemu/nodes".format(project_id=compute_project.id), base_params) diff --git a/tests/handlers/api/compute/test_vpcs.py b/tests/handlers/api/compute/test_vpcs.py index f75aba85..70ee8294 100644 --- a/tests/handlers/api/compute/test_vpcs.py +++ b/tests/handlers/api/compute/test_vpcs.py @@ -15,13 +15,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import pytest +import pytest_asyncio import uuid from tests.utils import asyncio_patch from unittest.mock import patch -@pytest.fixture +@pytest_asyncio.fixture async def vm(compute_api, compute_project): params = {"name": "PC TEST 1"} diff --git a/tests/handlers/api/controller/test_link.py b/tests/handlers/api/controller/test_link.py index be87b74b..67c77a47 100644 --- a/tests/handlers/api/controller/test_link.py +++ b/tests/handlers/api/controller/test_link.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import pytest +import pytest_asyncio from unittest.mock import patch, MagicMock from tests.utils import asyncio_patch, AsyncioMagicMock @@ -24,7 +24,7 @@ from gns3server.controller.ports.ethernet_port import EthernetPort from gns3server.controller.link import Link, FILTERS -@pytest.fixture +@pytest_asyncio.fixture async def nodes(compute, project): response = MagicMock() diff --git a/tests/handlers/api/controller/test_project.py b/tests/handlers/api/controller/test_project.py index ed8aeb22..035c96b4 100644 --- a/tests/handlers/api/controller/test_project.py +++ b/tests/handlers/api/controller/test_project.py @@ -18,6 +18,7 @@ import uuid import os import pytest +import pytest_asyncio import zipfile import json @@ -25,7 +26,7 @@ from unittest.mock import patch, MagicMock from tests.utils import asyncio_patch -@pytest.fixture +@pytest_asyncio.fixture async def project(controller_api, controller): u = str(uuid.uuid4()) diff --git a/tests/handlers/api/controller/test_snapshot.py b/tests/handlers/api/controller/test_snapshot.py index faed67df..034470c8 100644 --- a/tests/handlers/api/controller/test_snapshot.py +++ b/tests/handlers/api/controller/test_snapshot.py @@ -17,10 +17,10 @@ import os import uuid -import pytest +import pytest_asyncio -@pytest.fixture +@pytest_asyncio.fixture async def project(controller_api, controller): u = str(uuid.uuid4()) @@ -30,7 +30,7 @@ async def project(controller_api, controller): return project -@pytest.fixture +@pytest_asyncio.fixture async def snapshot(project): snapshot = await project.snapshot("test") diff --git a/tests/pytest.ini b/tests/pytest.ini new file mode 100644 index 00000000..2f4c80e3 --- /dev/null +++ b/tests/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +asyncio_mode = auto diff --git a/tests/test_config.py b/tests/test_config.py index f670ad54..cdaa346e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -53,7 +53,7 @@ def write_config(tmpdir, settings): return path -def test_get_section_config(loop, tmpdir): +def test_get_section_config(tmpdir): config = load_config(tmpdir, { "Server": { @@ -63,7 +63,7 @@ def test_get_section_config(loop, tmpdir): assert dict(config.get_section_config("Server")) == {"host": "127.0.0.1"} -def test_set_section_config(loop, tmpdir): +def test_set_section_config(tmpdir): config = load_config(tmpdir, { "Server": { @@ -77,7 +77,7 @@ def test_set_section_config(loop, tmpdir): assert dict(config.get_section_config("Server")) == {"host": "192.168.1.1", "local": "true"} -def test_set(loop, tmpdir): +def test_set(tmpdir): config = load_config(tmpdir, { "Server": { @@ -90,7 +90,7 @@ def test_set(loop, tmpdir): assert dict(config.get_section_config("Server")) == {"host": "192.168.1.1"} -def test_reload(loop, tmpdir): +def test_reload(tmpdir): config = load_config(tmpdir, { "Server": { diff --git a/tests/utils/test_asyncio.py b/tests/utils/test_asyncio.py index 9e66c124..f9f45feb 100644 --- a/tests/utils/test_asyncio.py +++ b/tests/utils/test_asyncio.py @@ -44,7 +44,7 @@ async def test_exception_wait_run_in_executor(): @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") -async def test_subprocess_check_output(loop, tmpdir): +async def test_subprocess_check_output(tmpdir): path = str(tmpdir / "test") result = await subprocess_check_output("echo", "-n", path) diff --git a/tests/web/test_response.py b/tests/web/test_response.py index 837f8163..3c29abcb 100644 --- a/tests/web/test_response.py +++ b/tests/web/test_response.py @@ -39,7 +39,7 @@ def response(): # assert response.status == 200 -async def test_response_file_not_found(loop, tmpdir, response): +async def test_response_file_not_found(tmpdir, response): filename = str(tmpdir / 'hello-not-found') with pytest.raises(HTTPNotFound):