diff options
-rw-r--r-- | delivery_merge/merge.py | 25 | ||||
-rw-r--r-- | tests/test_merge.py | 4 |
2 files changed, 16 insertions, 13 deletions
diff --git a/delivery_merge/merge.py b/delivery_merge/merge.py index 87b0cc9..fb291a2 100644 --- a/delivery_merge/merge.py +++ b/delivery_merge/merge.py @@ -175,21 +175,22 @@ def integration_test(pkg_data, conda_env, results_root='.'): def force_xunit2(project='.'): configs = [os.path.abspath(os.path.join(project, x)) - for x in ['pytest.ini', 'setup.cfg']] - create_config = not all([os.path.exists(x) for x in configs]) + for x in ['pytest.ini', 'setup.cfg']] - if create_config: + if any([os.path.exists(x) for x in configs]): + for filename in configs: + if not os.path.exists(filename): + continue + + cfg = ConfigParser() + cfg.read(filename) + cfg['tool:pytest'] = {'junit_family': 'xunit2'} + with open(filename, 'w') as data: + cfg.write(data) + break + else: data = """[pytest]\njunit_family = xunit2\n""" with open('pytest.ini', 'w+') as cfg: cfg.write(data) return - for filename in configs: - if not os.path.exists(filename): - continue - - cfg = ConfigParser() - cfg.read(filename) - cfg['tool:pytest']['junit_family'] = 'xunit2' - cfg.write(filename) - break diff --git a/tests/test_merge.py b/tests/test_merge.py index f604348..b6a885f 100644 --- a/tests/test_merge.py +++ b/tests/test_merge.py @@ -135,10 +135,10 @@ class TestMerge: assert contents.startswith('<?xml') and contents.endswith('</testsuite>') def test_force_xunit2_no_config(self): - assert not os.path.exists('pytest.ini') merge.force_xunit2() assert os.path.exists('pytest.ini') assert 'junit_family = xunit2' in open('pytest.ini').read() + os.remove('pytest.ini') def test_force_xunit2_no_setup(self): open('pytest.ini', 'w+').write('') @@ -146,6 +146,7 @@ class TestMerge: assert not os.path.exists('setup.cfg') assert os.path.exists('pytest.ini') assert 'junit_family = xunit2' in open('pytest.ini').read() + os.remove('pytest.ini') def test_force_xunit2_no_pytest(self): open('setup.cfg', 'w+').write('') @@ -153,4 +154,5 @@ class TestMerge: assert not os.path.exists('pytest.ini') assert os.path.exists('setup.cfg') assert 'junit_family = xunit2' in open('setup.cfg').read() + os.remove('setup.cfg') |