Swift from pytest to testr for unittests

Freezer currently uses pytest to execute unittests.
As we need to be consistent with the frameworks by the
other OS project, we are porting our tests to tests.

Change-Id: Ib755771efe496e467079dc2e990ca89a2e513eb6
Implements blueprint: swift-to-testr
This commit is contained in:
Fausto Marzi 2015-10-15 15:26:31 +01:00
parent 9fbe4fe5c3
commit 5902b0f7cd
13 changed files with 58 additions and 35 deletions

9
.testr.conf Normal file
View File

@ -0,0 +1,9 @@
[DEFAULT]
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_LOG_CAPTURE=${OS_LOG_CAPTURE:-1} \
${PYTHON:-python} -m subunit.run discover -s ${OS_TEST_PATH:-./tests} -t . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
group_regex=([^\.]+\.)+

View File

@ -1,5 +1,5 @@
import socket
from time import time, sleep
import time
class ThrottledSocket(object):
@ -15,15 +15,15 @@ class ThrottledSocket(object):
return setattr(self._wrappedsock, attr, value)
def recv(self, *args):
start = time()
start = time.time()
buf = self._wrappedsock.recv(*args)
self._sleep(len(buf), self.download_limit, start, time())
self._sleep(len(buf), self.download_limit, start, time.time())
return buf
def sendall(self, *args):
start = time()
start = time.time()
res = self._wrappedsock.send(*args)
self._sleep(res, self.upload_limit, start, time())
self._sleep(res, self.upload_limit, start, time.time())
@staticmethod
def _sleep_duration(transmitted, limit, start_time, end_time):
@ -40,7 +40,7 @@ class ThrottledSocket(object):
start_time,
end_time)
if sleep_duration > 0:
sleep(sleep_duration)
time.sleep(sleep_duration)
def makefile(self, mode='r', bufsize=-1):
return socket._fileobject(self, mode, bufsize)

View File

@ -19,14 +19,14 @@ Hudson (tjh@cryptsoft.com).
========================================================================
"""
import sys
import datetime
import sys
import time
from freezer import utils
from freezer import backup
from freezer import exec_cmd
from freezer import restore
from freezer import utils
import logging

View File

@ -13,3 +13,5 @@ pymongo>=2.6.3,<3.0
apscheduler
# Not in global-requirements
pep3143daemon
paramiko>=1.13.0

View File

@ -1,5 +1,10 @@
pytest
flake8>=2.2.4,<=2.4.1
mock>=1.1,!=1.1.4;python_version!='2.6'
mock==1.0.1;python_version=='2.6'
pylint>=1.3.1
hacking>=0.10.2,<0.11
coverage>=3.6
discover
mock>=1.0
oslosphinx
sphinx>=1.1.2,<1.2
testrepository>=0.0.18
testtools>=0.9.34

View File

@ -1,11 +1,10 @@
import tempfile
import shutil
import pytest
from freezer.storage import local
from freezer import utils
@pytest.mark.incremental
class TestLocalStorage(object):
BACKUP_DIR_PREFIX = "freezer_test_backup_dir"
FILES_DIR_PREFIX = "freezer_test_files_dir"

View File

@ -1,6 +1,5 @@
from freezer.bandwidth import ThrottledSocket, monkeypatch_bandwidth
from commons import FakeSocket
import pytest
class TestBandwidth:

View File

@ -30,7 +30,6 @@ from freezer import (restore, backup)
from freezer.job import Job, InfoJob, AdminJob, BackupJob, RestoreJob, create_job
import logging
from mock import patch, Mock
import pytest
import unittest

View File

@ -24,7 +24,6 @@ from commons import FakeSys
from freezer import job
from freezer.main import freezer_main
import pytest
import sys
'''

View File

@ -1,5 +1,4 @@
from freezer import utils
import pytest
import datetime
from commons import *

View File

@ -22,8 +22,6 @@ import subprocess
import os
import logging
import pytest
class TestVss:

View File

@ -21,8 +21,6 @@ from freezer import winutils
from commons import *
import logging
import pytest
class TestWinutils:

42
tox.ini
View File

@ -5,17 +5,9 @@ skipsdist = True
[testenv]
usedevelop = True
deps =
pytest
coverage
flake8
pytest-cov
pytest-xdist
pymysql
python-openstackclient>=1.0.3,<1.1.0
mock
pep3143daemon
apscheduler
pylint>=1.3.1
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
passenv =
FREEZER_TEST_SSH_KEY
FREEZER_TEST_SSH_USERNAME
@ -30,12 +22,28 @@ passenv =
install_command = pip install -U {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
commands = py.test -v --cov-report term-missing --cov freezer
[pytest]
whitelist_externals =
coverage
rm
commands =
python setup.py testr --coverage --testr-args="{posargs}"
coverage report -m
rm -f .coverage
python_files = test_*.py
norecursedirs = .tox .venv freezer_api freezer/binaries
[testend:venv]
commands = {posargs}
[tox:jenkins]
downloadcache = ~/cache/pip
[testenv:cover]
commands = python setup.py testr --coverage
[testenv:pep8]
commands = flake8 freezer
@ -43,5 +51,13 @@ commands = flake8 freezer
commands = pylint --rcfile .pylintrc freezer bin/freezerc
[flake8]
# it's not a bug that we aren't using all of hacking
# H102 -> apache2 license exists
# H103 -> license is apache
# H201 -> no bare excepts
# H501 -> don't use locals() for str formatting
# H903 -> \n not \r\n
ignore = H
select = H102, H103, H201, H501, H903, H201, H306, H301, H233
show-source = True
exclude = .venv,.tox,dist,doc,test,*egg,tests