From 95f11aa9410c8db4794b51932931e6ee3da46402 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 04:25:32 +0100 Subject: Make tests run with either nosetests or pytest And remove explicit dependencies on nose, replacing with pytest. The former is the way forward, for it is a better maintained test library, and a transitive dependency of `molecule`, the test framework we're using to add integration tests to this repo (work in progress). --- .../test/openshift_master_facts_bad_input_tests.py | 65 +++++++++++----------- ...nshift_master_facts_default_predicates_tests.py | 11 ++-- ...nshift_master_facts_default_priorities_tests.py | 11 ++-- 3 files changed, 42 insertions(+), 45 deletions(-) (limited to 'roles/openshift_master_facts') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py index ec6c7ae4a..e8da1e04a 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py @@ -3,7 +3,7 @@ import os import sys from ansible.errors import AnsibleError -from nose.tools import raises +import pytest sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) @@ -11,48 +11,47 @@ from openshift_master_facts_default_predicates import LookupModule # noqa: E402 class TestOpenShiftMasterFactsBadInput(object): - def setUp(self): - self.lookup = LookupModule() - self.default_facts = { - 'openshift': { - 'common': {} - } + lookup = LookupModule() + default_facts = { + 'openshift': { + 'common': {} } + } - @raises(AnsibleError) def test_missing_openshift_facts(self): - facts = {} - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = {} + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_missing_deployment_type(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '10.10' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '10.10' + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_missing_short_version_and_missing_openshift_release(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['deployment_type'] = 'origin' + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_unknown_deployment_types(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '1.1' - facts['openshift']['common']['deployment_type'] = 'bogus' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '1.1' + facts['openshift']['common']['deployment_type'] = 'bogus' + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_unknown_origin_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'origin' + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_unknown_ocp_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' + self.lookup.run(None, variables=facts) diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index 855f42273..51547ce7e 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -86,13 +86,12 @@ TEST_VARS = [ class TestOpenShiftMasterFactsDefaultPredicates(object): - def setUp(self): - self.lookup = LookupModule() - self.default_facts = { - 'openshift': { - 'common': {} - } + lookup = LookupModule() + default_facts = { + 'openshift': { + 'common': {} } + } def test_openshift_version(self): for regions_enabled in (True, False): diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index d27a48ede..4fb900b98 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -74,13 +74,12 @@ TEST_VARS = [ class TestOpenShiftMasterFactsDefaultPredicates(object): - def setUp(self): - self.lookup = LookupModule() - self.default_facts = { - 'openshift': { - 'common': {} - } + lookup = LookupModule() + default_facts = { + 'openshift': { + 'common': {} } + } def test_openshift_version(self): for zones_enabled in (True, False): -- cgit v1.2.3