Skip to content

Commit

Permalink
tests: s/nosetests/pytest/
Browse files Browse the repository at this point in the history
- Requires us to add pytest.ini to tell pytest where to look for test
  files, and set the python path.
- Mock drops terminal from the tested code, so we have to "mock" it in
  test_colors()
- Enable coverage in tox tests.
  • Loading branch information
praiskup committed Oct 3, 2024
1 parent 6ef9663 commit 68b254e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*$py.class
*.swp
*.swo
.noseids
*.patch
*#
*~
Expand All @@ -14,6 +13,7 @@ MANIFEST
dist
build
.build
.coverage
titorc.5
titorc.5.xml
tito.8
Expand Down
7 changes: 3 additions & 4 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ an authoring environment, too.

To run all tests, install these packages:

* python-nose, python-pep8, python-mock (for epl-6 and fedora) and rpm-python
* python3-nose, python3-pep8, python3-mock (for epl-6 and fedora) , and rpm-python3
* pytest, python-pep8, python-mock (for epl-6 and fedora) and rpm-python
* pytest, python3-pep8, python3-mock (for epl-6 and fedora) , and rpm-python3
* createrepo_c
* git-annex

Expand All @@ -98,8 +98,7 @@ for python 2.4 - 2.7 (in case you don't have pip, install via yum python-pip pac

Then from the root of the project:

python ./runtests.py -vv
python3 ./runtests.py -vv
./runtests.sh


### Advanced
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
python_files = test/*.py test/*/*.py
pythonpath = src
48 changes: 0 additions & 48 deletions runtests.py

This file was deleted.

10 changes: 10 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash -e
cov=--cov
args=()
for arg; do
case $arg in
--no-cov) cov= ;;
*) args+=( "$arg" )
esac
done
exec python3 -m pytest -vv $cov "${args[@]}"
7 changes: 2 additions & 5 deletions test/functional/build_gitannex_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import tempfile
import sys
import shutil
from nose.plugins.skip import SkipTest
from os.path import join
from pytest import skip

from functional.fixture import TitoGitTestFixture, tito

Expand All @@ -41,12 +41,9 @@ def setUp(self):
# Guess based on python version.
# Do not use anything based on uname in case we are in container.
# Do not use `lsb_release` to avoid dependencies.
if sys.version[0:3] == '2.4':
raise SkipTest('git-annex is not available in epel-5')

status, ga_version = getstatusoutput('rpm -q git-annex')
if status != 0:
raise SkipTest("git-annex is missing")
skip("git-annex is missing")

# Setup test config:
self.config = RawConfigParser()
Expand Down
8 changes: 5 additions & 3 deletions test/unit/common_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ def test_turn_off_colors(self, mock_user_conf):
def test_colors(self, mock_user_conf):
mock_user_conf.return_value = {}
stream = StringIO()
_out('Hello world', None, Terminal().red, stream)
# RHEL 6 doesn't have self.assertRegexpMatches unfortunately
self.assertTrue(re.match('.+Hello world.+\n', stream.getvalue()))
with patch("blessed.terminal.os.isatty") as isatty:
_out('Hello world', None, Terminal().red, stream)
isatty.return_value = True
# RHEL 6 doesn't have self.assertRegexpMatches unfortunately
self.assertTrue(re.match('.+Hello world.+\n', stream.getvalue()))

def test_get_project_name(self):
TAGS = [
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ skipsdist = True


[testenv]
deps = nose
commands = nosetests {posargs}
deps = pytest pytest-cov
commands =
python -m pytest -v {posargs} --cov-report term-missing --cov-branch --cov

0 comments on commit 68b254e

Please sign in to comment.