Skip to content

Commit

Permalink
ceph-volume/tests: address nose tests deprecation
Browse files Browse the repository at this point in the history
migrate setup/teardown from nosetest to native pytest.

see [1]

[1] https://docs.pytest.org/en/stable/deprecations.html#support-for-tests-written-for-nose

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
  • Loading branch information
guits committed May 15, 2023
1 parent cda1b14 commit 2f78121
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/ceph-volume/ceph_volume/tests/api/test_lvm.py
Expand Up @@ -69,7 +69,7 @@ def test_integer_gets_produced(self):

class TestCreateLVs(object):

def setup(self):
def setup_method(self):
self.vg = api.VolumeGroup(vg_name='ceph',
vg_extent_size=1073741824,
vg_extent_count=99999999,
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_fallback_to_one_part(self, monkeypatch):

class TestVolumeGroupSizing(object):

def setup(self):
def setup_method(self):
self.vg = api.VolumeGroup(vg_name='ceph',
vg_extent_size=1073741824,
vg_free_count=1024)
Expand Down Expand Up @@ -182,7 +182,7 @@ def mock_call(cmd, **kw):

class TestCreateLV(object):

def setup(self):
def setup_method(self):
self.foo_volume = api.Volume(lv_name='foo', lv_path='/path', vg_name='foo_group', lv_tags='')
self.foo_group = api.VolumeGroup(vg_name='foo_group',
vg_extent_size="4194304",
Expand Down Expand Up @@ -294,7 +294,7 @@ def test_create_vg(self, m_get_single_lv, m_create_vg, m_get_device_vgs, m_call,

class TestTags(object):

def setup(self):
def setup_method(self):
self.foo_volume_clean = api.Volume(lv_name='foo_clean', lv_path='/pathclean',
vg_name='foo_group',
lv_tags='')
Expand Down Expand Up @@ -373,7 +373,7 @@ def test_clear_tags(self, monkeypatch, capture):

class TestExtendVG(object):

def setup(self):
def setup_method(self):
self.foo_volume = api.VolumeGroup(vg_name='foo', lv_tags='')

def test_uses_single_device_in_list(self, monkeypatch, fake_run):
Expand All @@ -397,7 +397,7 @@ def test_uses_multiple_devices(self, monkeypatch, fake_run):

class TestReduceVG(object):

def setup(self):
def setup_method(self):
self.foo_volume = api.VolumeGroup(vg_name='foo', lv_tags='')

def test_uses_single_device_in_list(self, monkeypatch, fake_run):
Expand All @@ -421,7 +421,7 @@ def test_uses_multiple_devices(self, monkeypatch, fake_run):

class TestCreateVG(object):

def setup(self):
def setup_method(self):
self.foo_volume = api.VolumeGroup(vg_name='foo', lv_tags='')

def test_no_name(self, monkeypatch, fake_run):
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/devices/lvm/test_zap.py
Expand Up @@ -220,7 +220,7 @@ def test_ensure_associated_lvs(self, m_get_lvs):

class TestWipeFs(object):

def setup(self):
def setup_method(self):
os.environ['CEPH_VOLUME_WIPEFS_INTERVAL'] = '0'

def test_works_on_second_try(self, stub_call):
Expand Down
Expand Up @@ -5,7 +5,7 @@

class TestGetContents(object):

def setup(self):
def setup_method(self):
self.magic_file_name = '/tmp/magic-file'

def test_multiple_lines_are_left_as_is(self, fake_filesystem):
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/systemd/test_main.py
Expand Up @@ -28,7 +28,7 @@ def __call__(self, *a, **kw):

class TestMain(object):

def setup(self):
def setup_method(self):
conf.log_path = '/tmp/'

def test_no_arguments_parsing_error(self):
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/test_configuration.py
Expand Up @@ -19,7 +19,7 @@

class TestConf(object):

def setup(self):
def setup_method(self):
self.conf_file = StringIO(dedent("""
[foo]
default = 0
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/test_decorators.py
Expand Up @@ -46,7 +46,7 @@ class Error(Exception):

class TestCatches(object):

def teardown(self):
def teardown_method(self):
try:
del(os.environ['CEPH_VOLUME_DEBUG'])
except KeyError:
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/test_terminal.py
Expand Up @@ -100,7 +100,7 @@ def make_stream(buffer, encoding):

class TestWriteUnicode(object):

def setup(self):
def setup_method(self):
self.octpus_and_squid_en = u'octpus and squid'
self.octpus_and_squid_zh = u'章鱼和鱿鱼'
self.message = self.octpus_and_squid_en + self.octpus_and_squid_zh
Expand Down
18 changes: 9 additions & 9 deletions src/ceph-volume/ceph_volume/tests/util/test_arg_validators.py
Expand Up @@ -8,7 +8,7 @@

class TestOSDPath(object):

def setup(self):
def setup_method(self):
self.validator = arg_validators.OSDPath()

def test_is_not_root(self, monkeypatch):
Expand All @@ -34,7 +34,7 @@ def test_files_are_missing(self, is_root, tmpdir, monkeypatch):

class TestExcludeGroupOptions(object):

def setup(self):
def setup_method(self):
self.parser = argparse.ArgumentParser()

def test_flags_in_one_group(self):
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_flags_conflict(self, capsys):

class TestValidDevice(object):

def setup(self, fake_filesystem):
def setup_method(self, fake_filesystem):
self.validator = arg_validators.ValidDevice()

@patch('ceph_volume.util.arg_validators.disk.has_bluestore_label', return_value=False)
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_dev_has_partitions(self, m_get_single_lv, m_has_bs_label, mocked_device
self.validator('/dev/foo')

class TestValidZapDevice(object):
def setup(self):
def setup_method(self):
self.validator = arg_validators.ValidZapDevice()

@patch('ceph_volume.util.arg_validators.Device')
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_device_has_no_partition(self, m_get_single_lv, m_has_bs_label, mocked_
assert self.validator('/dev/foo')

class TestValidDataDevice(object):
def setup(self):
def setup_method(self):
self.validator = arg_validators.ValidDataDevice()

@patch('ceph_volume.util.arg_validators.Device')
Expand Down Expand Up @@ -194,7 +194,7 @@ def test_device_has_bs_signature(self, m_get_single_lv, m_has_bs_label, mocked_
self.validator('/dev/foo')

class TestValidRawDevice(object):
def setup(self):
def setup_method(self):
self.validator = arg_validators.ValidRawDevice()

@patch('ceph_volume.util.arg_validators.Device')
Expand Down Expand Up @@ -268,7 +268,7 @@ def mock_call(cmd, **kw):
assert self.validator('/dev/foo')

class TestValidBatchDevice(object):
def setup(self):
def setup_method(self):
self.validator = arg_validators.ValidBatchDevice()

@patch('ceph_volume.util.arg_validators.Device')
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_device_is_not_partition(self, m_get_single_lv, m_has_bs_label, mocked_
assert self.validator('/dev/foo')

class TestValidBatchDataDevice(object):
def setup(self):
def setup_method(self):
self.validator = arg_validators.ValidBatchDataDevice()

@patch('ceph_volume.util.arg_validators.Device')
Expand Down Expand Up @@ -340,7 +340,7 @@ def test_device_is_not_partition(self, m_get_single_lv, m_has_bs_label, mocked_

class TestValidFraction(object):

def setup(self):
def setup_method(self):
self.validator = arg_validators.ValidFraction()

def test_fraction_is_valid(self, fake_call):
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/util/test_device.py
Expand Up @@ -592,7 +592,7 @@ def test_lv_is_not_encrypted_lvm_api(self, fake_call, factory, device_info):

class TestDeviceOrdering(object):

def setup(self):
def setup_method(self):
self.data = {
"/dev/sda": {"removable": 0},
"/dev/sdb": {"removable": 1}, # invalid
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-volume/ceph_volume/tests/util/test_system.py
Expand Up @@ -264,7 +264,7 @@ def apply(value='/bin/restorecon'):

class TestSetContext(object):

def setup(self):
def setup_method(self):
try:
os.environ.pop('CEPH_VOLUME_SKIP_RESTORECON')
except KeyError:
Expand Down

0 comments on commit 2f78121

Please sign in to comment.