summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-03-20 14:12:06 +0000
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-03-21 09:21:09 +0000
commitbde70c9585507b315245dd333481aebc7b516d0a (patch)
tree788faecb564e0ebf6a748ea9a188dc99654b9e28
parente1b1e6c9d552cd960e1531023ead44c9f3408b45 (diff)
downloadbuildstream-bschubert/better-pytest-report.tar.gz
tests: when comparing lists/dicts, compare all at oncebschubert/better-pytest-report
This allows pytest to show a better report of the difference between the two lists and not just tell that one entry is wrong.
-rw-r--r--tests/cachekey/cachekey.py7
-rw-r--r--tests/elements/filter.py13
-rw-r--r--tests/format/dependencies.py59
-rw-r--r--tests/frontend/artifact.py6
-rw-r--r--tests/frontend/push.py14
-rw-r--r--tests/frontend/track.py12
6 files changed, 61 insertions, 50 deletions
diff --git a/tests/cachekey/cachekey.py b/tests/cachekey/cachekey.py
index 2bc60582a..f352dad3d 100644
--- a/tests/cachekey/cachekey.py
+++ b/tests/cachekey/cachekey.py
@@ -255,6 +255,7 @@ def test_keys_stable_over_targets(cli, datafiles):
ordering2_result.assert_success()
ordering2_cache_keys = parse_output_keys(ordering2_result.output)
- for element in ordering1_cache_keys:
- assert ordering1_cache_keys[element] == ordering2_cache_keys[element]
- assert ordering1_cache_keys[element] == all_cache_keys[element]
+ keys = ordering1_cache_keys.keys()
+
+ assert {key: ordering2_cache_keys[key] for key in keys} == ordering1_cache_keys
+ assert {key: all_cache_keys[key] for key in keys} == ordering1_cache_keys
diff --git a/tests/elements/filter.py b/tests/elements/filter.py
index 94a704c92..c8be210aa 100644
--- a/tests/elements/filter.py
+++ b/tests/elements/filter.py
@@ -396,8 +396,11 @@ def test_filter_track_multi(datafiles, cli, tmpdir):
# Assert that a fetch is needed
states = cli.get_element_states(project, [input_name, input2_name])
- assert states[input_name] == 'no reference'
- assert states[input2_name] == 'no reference'
+
+ assert states == {
+ input_name: "no reference",
+ input2_name: "no reference",
+ }
# Now try to track it
result = cli.run(project=project, args=["source", "track", "filter1.bst", "filter2.bst"])
@@ -458,8 +461,10 @@ def test_filter_track_multi_exclude(datafiles, cli, tmpdir):
# Assert that a fetch is needed
states = cli.get_element_states(project, [input_name, input2_name])
- assert states[input_name] == 'no reference'
- assert states[input2_name] == 'no reference'
+ assert states == {
+ input_name: "no reference",
+ input2_name: "no reference",
+ }
# Now try to track it
result = cli.run(project=project, args=["source", "track", "filter1.bst", "filter2.bst", "--except", input_name])
diff --git a/tests/format/dependencies.py b/tests/format/dependencies.py
index e0f517249..780eac73e 100644
--- a/tests/format/dependencies.py
+++ b/tests/format/dependencies.py
@@ -147,15 +147,15 @@ def test_scope_all(cli, datafiles):
element_list = cli.get_pipeline(project, elements, scope='all')
- assert len(element_list) == 7
-
- assert element_list[0] == "build-build.bst"
- assert element_list[1] == "run-build.bst"
- assert element_list[2] == "build.bst"
- assert element_list[3] == "dep-one.bst"
- assert element_list[4] == "run.bst"
- assert element_list[5] == "dep-two.bst"
- assert element_list[6] == "target.bst"
+ assert element_list == [
+ "build-build.bst",
+ "run-build.bst",
+ "build.bst",
+ "dep-one.bst",
+ "run.bst",
+ "dep-two.bst",
+ "target.bst",
+ ]
@pytest.mark.datafiles(DATA_DIR)
@@ -165,12 +165,12 @@ def test_scope_run(cli, datafiles):
element_list = cli.get_pipeline(project, elements, scope='run')
- assert len(element_list) == 4
-
- assert element_list[0] == "dep-one.bst"
- assert element_list[1] == "run.bst"
- assert element_list[2] == "dep-two.bst"
- assert element_list[3] == "target.bst"
+ assert element_list == [
+ "dep-one.bst",
+ "run.bst",
+ "dep-two.bst",
+ "target.bst",
+ ]
@pytest.mark.datafiles(DATA_DIR)
@@ -180,11 +180,7 @@ def test_scope_build(cli, datafiles):
element_list = cli.get_pipeline(project, elements, scope='build')
- assert len(element_list) == 3
-
- assert element_list[0] == "dep-one.bst"
- assert element_list[1] == "run.bst"
- assert element_list[2] == "dep-two.bst"
+ assert element_list == ["dep-one.bst", "run.bst", "dep-two.bst"]
@pytest.mark.datafiles(DATA_DIR)
@@ -200,10 +196,7 @@ def test_scope_build_of_child(cli, datafiles):
# Pass two, let's look at these
element_list = cli.get_pipeline(project, [element], scope='build')
- assert len(element_list) == 2
-
- assert element_list[0] == "run-build.bst"
- assert element_list[1] == "build.bst"
+ assert element_list == ["run-build.bst", "build.bst"]
@pytest.mark.datafiles(DATA_DIR)
@@ -216,12 +209,12 @@ def test_no_recurse(cli, datafiles):
# show` option does this directly.
element_list = cli.get_pipeline(project, elements, scope='plan')
- assert len(element_list) == 7
-
- assert element_list[0] == 'build-build.bst'
- assert element_list[1] in ['build.bst', 'run-build.bst']
- assert element_list[2] in ['build.bst', 'run-build.bst']
- assert element_list[3] in ['dep-one.bst', 'run.bst', 'dep-two.bst']
- assert element_list[4] in ['dep-one.bst', 'run.bst', 'dep-two.bst']
- assert element_list[5] in ['dep-one.bst', 'run.bst', 'dep-two.bst']
- assert element_list[6] == 'target.bst'
+ assert element_list == [
+ 'build-build.bst',
+ 'run-build.bst',
+ 'build.bst',
+ 'dep-one.bst',
+ 'run.bst',
+ 'dep-two.bst',
+ 'target.bst',
+ ]
diff --git a/tests/frontend/artifact.py b/tests/frontend/artifact.py
index 7ce9c337c..8cc6cc658 100644
--- a/tests/frontend/artifact.py
+++ b/tests/frontend/artifact.py
@@ -128,8 +128,10 @@ def test_artifact_delete_element_and_artifact(cli, tmpdir, datafiles):
# First build an element so that we can find its artifact
result = cli.run(project=project, args=['build', element])
result.assert_success()
- assert cli.get_element_state(project, element) == 'cached'
- assert cli.get_element_state(project, dep) == 'cached'
+ assert cli.get_element_states(project, [element, dep], deps="none") == {
+ element: "cached",
+ dep: "cached",
+ }
# Obtain the artifact ref
cache_key = cli.get_element_key(project, element)
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index ab6b455f2..dcd237204 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -253,8 +253,12 @@ def test_artifact_expires(cli, datafiles, tmpdir):
# check that element's 1 and 2 are cached both locally and remotely
states = cli.get_element_states(project, ['element1.bst', 'element2.bst'])
- assert states['element1.bst'] == 'cached'
- assert states['element2.bst'] == 'cached'
+
+ assert states == {
+ "element1.bst": "cached",
+ "element2.bst": "cached",
+ }
+
assert_shared(cli, share, project, 'element1.bst')
assert_shared(cli, share, project, 'element2.bst')
@@ -339,8 +343,10 @@ def test_recently_pulled_artifact_does_not_expire(cli, datafiles, tmpdir):
# Ensure they are cached locally
states = cli.get_element_states(project, ['element1.bst', 'element2.bst'])
- assert states['element1.bst'] == 'cached'
- assert states['element2.bst'] == 'cached'
+ assert states == {
+ "element1.bst": "cached",
+ "element2.bst": "cached",
+ }
# Ensure that they have been pushed to the cache
assert_shared(cli, share, project, 'element1.bst')
diff --git a/tests/frontend/track.py b/tests/frontend/track.py
index 2660b25de..7a368d71d 100644
--- a/tests/frontend/track.py
+++ b/tests/frontend/track.py
@@ -51,8 +51,10 @@ def test_track_single(cli, tmpdir, datafiles):
# Assert that tracking is needed for both elements
states = cli.get_element_states(project, [element_target_name])
- assert states[element_dep_name] == 'no reference'
- assert states[element_target_name] == 'no reference'
+ assert states == {
+ element_dep_name: "no reference",
+ element_target_name: "no reference",
+ }
# Now first try to track only one element
result = cli.run(project=project, args=[
@@ -68,8 +70,10 @@ def test_track_single(cli, tmpdir, datafiles):
# Assert that the dependency is waiting and the target has still never been tracked
states = cli.get_element_states(project, [element_target_name])
- assert states[element_dep_name] == 'no reference'
- assert states[element_target_name] == 'waiting'
+ assert states == {
+ element_dep_name: 'no reference',
+ element_target_name: 'waiting',
+ }
@pytest.mark.datafiles(os.path.join(TOP_DIR))