Skip to content

Commit 569105a

Browse files
committed
refactor: don't use TYPE_CHECKING in tests/
It doesn't play well with the automatic import of a class in the IDE and is not needed in tests/, unlike in lib/ Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 43a9ffa commit 569105a

6 files changed

Lines changed: 26 additions & 46 deletions

File tree

tests/install/conftest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
import logging
77
import os
88
import tempfile
9-
import xml.etree.ElementTree as ET
109

1110
from data import ARP_SERVER, ISO_IMAGES, ISO_IMAGES_BASE, ISO_IMAGES_CACHE, TEST_SSH_PUBKEY, TOOLS
1211
from lib import installer, pxe
1312
from lib.commands import local_cmd
1413
from lib.common import callable_marker, url_download, wait_for
14+
from lib.host import Host
1515
from lib.installer import AnswerFile
16+
from lib.vm import VM
1617

17-
from typing import TYPE_CHECKING, Any, Generator, Sequence
18-
19-
if TYPE_CHECKING:
20-
from lib.host import Host
21-
from lib.vm import VM
18+
from typing import Generator, Sequence
2219

2320
# Return true if the version of the ISO doesn't support the source type.
2421
# Note: this is a quick-win hack, to avoid explicit enumeration of supported

tests/storage/glusterfs/conftest.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77

88
from lib import config
99
from lib.common import exec_nofail, raise_errors, setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
10+
from lib.host import Host
1011
from lib.netutil import is_ipv6
11-
12-
from typing import TYPE_CHECKING, Generator
13-
14-
if TYPE_CHECKING:
15-
from lib.host import Host
16-
from lib.pool import Pool
17-
from lib.sr import SR
18-
from lib.vdi import VDI
19-
from lib.vm import VM
12+
from lib.pool import Pool
13+
from lib.sr import SR
14+
from lib.vdi import VDI
15+
from lib.vm import VM
2016

2117
# explicit import for package-scope fixtures
2218
from pkgfixtures import (
@@ -29,6 +25,8 @@
2925
xfs_sr_on_hostB1,
3026
)
3127

28+
from typing import Generator
29+
3230
GLUSTERFS_PORTS = [('24007', 'tcp'), ('49152:49251', 'tcp')]
3331

3432
@dataclass

tests/storage/largeblock/conftest.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
import logging
66

77
from lib import config
8-
from lib.vdi import ImageFormat
8+
from lib.host import Host
9+
from lib.sr import SR
10+
from lib.vdi import VDI, ImageFormat
11+
from lib.vm import VM
912

10-
from typing import TYPE_CHECKING, Generator
11-
12-
if TYPE_CHECKING:
13-
from lib.host import Host
14-
from lib.sr import SR
15-
from lib.vdi import VDI
16-
from lib.vm import VM
13+
from typing import Generator
1714

1815
@pytest.fixture(scope='package')
1916
def largeblock_sr(host: Host,

tests/storage/largeblock/create_destroy/test_create_destroy_largeblock_sr.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
import pytest
44

55
from lib.common import vm_image
6+
from lib.host import Host
67
from lib.vdi import ImageFormat
78
from tests.storage import try_to_create_sr_with_missing_device
89

9-
from typing import TYPE_CHECKING
10-
11-
if TYPE_CHECKING:
12-
from lib.host import Host
13-
1410
# Requirements:
1511
# - one XCP-ng host with an additional unused 4KiB disk for the SR
1612

tests/storage/largeblock/test_largeblock_sr.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33
import pytest
44

55
from lib.common import vm_image, wait_for
6-
from lib.vdi import ImageFormat
6+
from lib.host import Host
7+
from lib.sr import SR
8+
from lib.vdi import VDI, ImageFormat
9+
from lib.vm import VM
710
from tests.storage import try_to_create_sr_with_missing_device, vdi_is_open
811

9-
from typing import TYPE_CHECKING
10-
11-
if TYPE_CHECKING:
12-
from lib.host import Host
13-
from lib.sr import SR
14-
from lib.vdi import VDI
15-
from lib.vm import VM
16-
1712
# Requirements:
1813
# - one XCP-ng host with an additional unused 4KiB disk for the SR
1914

tests/storage/linstor/conftest.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
import lib.commands as commands
1313
from lib import config
14-
from lib.common import safe_split
14+
from lib.host import Host
15+
from lib.pool import Pool
16+
from lib.sr import SR
17+
from lib.vdi import VDI
18+
from lib.vm import VM
1519

1620
try:
1721
from data import LINSTOR_REDUNDANCY # type: ignore
@@ -29,14 +33,7 @@
2933
xfs_sr_on_hostB1,
3034
)
3135

32-
from typing import TYPE_CHECKING, Generator
33-
34-
if TYPE_CHECKING:
35-
from lib.host import Host
36-
from lib.pool import Pool
37-
from lib.sr import SR
38-
from lib.vdi import VDI
39-
from lib.vm import VM
36+
from typing import Generator
4037

4138
GROUP_NAME = 'linstor_group'
4239
STORAGE_POOL_NAME = f'{GROUP_NAME}/thin_device'

0 commit comments

Comments
 (0)