mirror of
https://github.com/rpm-software-management/tito.git
synced 2025-02-23 04:02:46 +00:00
tests: s/nosetests/pytest/
- 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.
This commit is contained in:
parent
3ec27836f3
commit
6feb4f2d21
8 changed files with 31 additions and 63 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,7 +4,6 @@
|
|||
*$py.class
|
||||
*.swp
|
||||
*.swo
|
||||
.noseids
|
||||
*.patch
|
||||
*#
|
||||
*~
|
||||
|
@ -14,6 +13,7 @@ MANIFEST
|
|||
dist
|
||||
build
|
||||
.build
|
||||
.coverage
|
||||
titorc.5
|
||||
titorc.5.xml
|
||||
tito.8
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
|
3
pytest.ini
Normal file
3
pytest.ini
Normal file
|
@ -0,0 +1,3 @@
|
|||
[pytest]
|
||||
python_files = test/*.py test/*/*.py
|
||||
pythonpath = src
|
48
runtests.py
48
runtests.py
|
@ -1,48 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
#
|
||||
# Copyright (c) 2008-2009 Red Hat, Inc.
|
||||
#
|
||||
# This software is licensed to you under the GNU General Public License,
|
||||
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
||||
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
||||
# along with this software; if not, see
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
||||
#
|
||||
# Red Hat trademarks are not licensed under GPLv2. No permission is
|
||||
# granted to use or replicate Red Hat trademarks that are incorporated
|
||||
# in this software or its documentation.
|
||||
"""
|
||||
Executes all tests.
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import nose
|
||||
|
||||
# Make sure we run from the source, this is tricky because the functional
|
||||
# tests need to find both the location of the 'tito' executable script,
|
||||
# and the internal tito code needs to know where to find our auxiliary Perl
|
||||
# scripts. Adding an environment variable hack to the actual code to
|
||||
# accommodate this for now.
|
||||
|
||||
TEST_SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
SRC_DIR = os.path.normpath(os.path.join(TEST_SCRIPT_DIR, "src/"))
|
||||
sys.path.insert(0, SRC_DIR)
|
||||
SRC_BIN_DIR = os.path.abspath(os.path.join(TEST_SCRIPT_DIR, "bin/"))
|
||||
|
||||
os.environ['TITO_SRC_BIN_DIR'] = SRC_BIN_DIR
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
print("Using Python %s" % sys.version)
|
||||
print("Using nose %s" % nose.__version__)
|
||||
print("Running tito tests against: %s" % SRC_DIR)
|
||||
|
||||
# Make sure no older test directories exist
|
||||
for dir in os.listdir(tempfile.gettempdir()):
|
||||
if dir.endswith('-titotest'):
|
||||
shutil.rmtree(os.path.join(tempfile.gettempdir(), dir))
|
||||
|
||||
nose.main()
|
10
runtests.sh
Executable file
10
runtests.sh
Executable file
|
@ -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[@]}"
|
|
@ -20,8 +20,8 @@ import glob
|
|||
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
|
||||
|
||||
|
@ -41,12 +41,9 @@ class GitAnnexBuilderTests(TitoGitTestFixture):
|
|||
# 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()
|
||||
|
|
|
@ -220,7 +220,9 @@ class CommonTests(unittest.TestCase):
|
|||
def test_colors(self, mock_user_conf):
|
||||
mock_user_conf.return_value = {}
|
||||
stream = StringIO()
|
||||
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()))
|
||||
|
||||
|
|
9
tox.ini
9
tox.ini
|
@ -17,5 +17,10 @@ skipsdist = True
|
|||
|
||||
|
||||
[testenv]
|
||||
deps = nose
|
||||
commands = nosetests {posargs}
|
||||
deps =
|
||||
-rrequirements.txt
|
||||
coverage
|
||||
pytest
|
||||
pytest-cov
|
||||
commands =
|
||||
python -m pytest -v {posargs} --cov-report term-missing --cov-branch --cov
|
||||
|
|
Loading…
Add table
Reference in a new issue