diff options
author | Benjamin Schubert <bschubert15@bloomberg.net> | 2019-12-02 11:34:31 +0000 |
---|---|---|
committer | Benjamin Schubert <bschubert15@bloomberg.net> | 2019-12-02 11:51:15 +0000 |
commit | e4ed02fbfcea355d6432e7a2e389af84a94120dd (patch) | |
tree | 6d42e69f8cd674a7be8041d1bcaf0f113762bb26 /tests | |
parent | 1064374cf19ef5492c3b6b4a23ae14c49ac8ea86 (diff) | |
download | buildstream-e4ed02fbfcea355d6432e7a2e389af84a94120dd.tar.gz |
tests: Use pytest.raise() instead of checking for return code
This gives a potentially more explicit understanding of what went
wrong, and pytest can give better information about that exception
than just us asserting the return code.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/external_plugins.py | 5 | ||||
-rw-r--r-- | tests/sources/git.py | 8 | ||||
-rw-r--r-- | tests/testutils/python_repo.py | 3 |
3 files changed, 8 insertions, 8 deletions
diff --git a/tests/external_plugins.py b/tests/external_plugins.py index 2123b846b..9a5e04501 100644 --- a/tests/external_plugins.py +++ b/tests/external_plugins.py @@ -31,12 +31,13 @@ class ExternalPluginRepo: def clone(self, location): self._clone_location = os.path.join(location, self.name) subprocess.run( - ["git", "clone", "--single-branch", "--branch", self.ref, "--depth", "1", self.url, self._clone_location,] + ["git", "clone", "--single-branch", "--branch", self.ref, "--depth", "1", self.url, self._clone_location,], + check=True, ) return self._clone_location def install(self): - subprocess.run(["pip3", "install", self._clone_location]) + subprocess.run(["pip3", "install", self._clone_location], check=True) def test(self, args): test_files = self._match_test_patterns() diff --git a/tests/sources/git.py b/tests/sources/git.py index fbb1394ec..e4252fe51 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -779,8 +779,8 @@ def test_git_describe(cli, tmpdir, datafiles, ref_storage, tag_type): tags = set(tags.splitlines()) assert tags == set(["tag1", "tag2"]) - p = subprocess.run(["git", "log", repo.rev_parse("uselesstag")], cwd=checkout) - assert p.returncode != 0 + with pytest.raises(subprocess.CalledProcessError): + subprocess.run(["git", "log", repo.rev_parse("uselesstag")], cwd=checkout, check=True) @pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") @@ -888,8 +888,8 @@ def test_git_describe_head_is_tagged(cli, tmpdir, datafiles, ref_storage, tag_ty assert set(rev_list.splitlines()) == set([tagged_ref]) - p = subprocess.run(["git", "log", repo.rev_parse("uselesstag")], cwd=checkout) - assert p.returncode != 0 + with pytest.raises(subprocess.CalledProcessError): + subprocess.run(["git", "log", repo.rev_parse("uselesstag")], cwd=checkout, check=True) @pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") diff --git a/tests/testutils/python_repo.py b/tests/testutils/python_repo.py index 7d9ae4e47..07efa376a 100644 --- a/tests/testutils/python_repo.py +++ b/tests/testutils/python_repo.py @@ -88,8 +88,7 @@ def generate_pip_package(tmpdir, pypi, name, version="0.1", dependencies=None): os.chmod(main_file, 0o644) # Run sdist with a fresh process - p = subprocess.run([sys.executable, "setup.py", "sdist"], cwd=tmpdir) - assert p.returncode == 0 + subprocess.run([sys.executable, "setup.py", "sdist"], cwd=tmpdir, check=True) # create directory for this package in pypi resulting in a directory # tree resembling the following structure: |