summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-06-22 15:03:05 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-07-21 15:14:56 -0700
commit63e56cf382acc7a3abd79dfb58c886979416ec2c (patch)
treee3248bcb41c6cf09d87b6a7a705e7bf83e2d94a2 /unittests
parent1a5a33fe0126f72dd374a5ea150d545822e60eb5 (diff)
unittests/framework: remove 'autouse' from fixture
This reworks the fixture to not use autouse, so that other tests can be added to the class without getting the setup it doesn't use. This also uses a class scope fixture instead of an instance scope one. Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
Diffstat (limited to 'unittests')
-rw-r--r--unittests/framework/backends/test_json.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/unittests/framework/backends/test_json.py b/unittests/framework/backends/test_json.py
index 8c2623c5b..c9a02ffb8 100644
--- a/unittests/framework/backends/test_json.py
+++ b/unittests/framework/backends/test_json.py
@@ -106,9 +106,10 @@ class TestJSONBackend(object):
name = grouptools.join('a', 'test', 'group', 'test1')
result = results.TestResult('pass')
- @pytest.fixture(autouse=True)
- def setup(self, tmpdir):
- test = backends.json.JSONBackend(six.text_type(tmpdir))
+ @pytest.fixture(scope='class')
+ def result_dir(self, tmpdir_factory):
+ directory = tmpdir_factory.mktemp('main')
+ test = backends.json.JSONBackend(six.text_type(directory))
test.initialize(shared.INITIAL_METADATA)
with test.write_test(self.name) as t:
t(self.result)
@@ -116,26 +117,28 @@ class TestJSONBackend(object):
{'time_elapsed':
results.TimeAttribute(start=0.0, end=1.0).to_json()})
- def test_metadata_removed(self, tmpdir):
- assert not tmpdir.join('metadata.json').check()
+ return directory
- def test_tests_directory_removed(self, tmpdir):
- assert not tmpdir.join('tests').check()
+ def test_metadata_removed(self, result_dir):
+ assert not result_dir.join('metadata.json').check()
- def test_results_file_created(self, tmpdir):
+ def test_tests_directory_removed(self, result_dir):
+ assert not result_dir.join('tests').check()
+
+ def test_results_file_created(self, result_dir):
# Normally this would also have a compression extension, but this
# module has a setup fixture that forces the compression to None.
- assert tmpdir.join('results.json').check()
+ assert result_dir.join('results.json').check()
- def test_results_are_json(self, tmpdir):
+ def test_results_are_json(self, result_dir):
# This only checks that the output is valid JSON, not that the
# schema is correct
- with tmpdir.join('results.json').open('r') as f:
+ with result_dir.join('results.json').open('r') as f:
json.load(f)
- def test_results_are_valid(self, tmpdir):
+ def test_results_are_valid(self, result_dir):
"""Test that the values produced are valid."""
- with tmpdir.join('results.json').open('r') as f:
+ with result_dir.join('results.json').open('r') as f:
json_ = json.load(f)
with open(SCHEMA, 'r') as f: