Skip to content

Commit

Permalink
Switch from nose to pytest
Browse files Browse the repository at this point in the history
The tests are moved to a top-level tests directory and the source is
moved down to a src/ directory, to deal with known issues in collecting
coverage with pytest when source is directly off the repo root.

The tests still use unittest style classes rather than taking advantage
of pytest.
  • Loading branch information
bmerry committed Aug 5, 2020
1 parent ebd139e commit 5e04267
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 30 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ python:
- 3.6
- 3.7
- 3.8
install: .travis/install.sh
script: .travis/run.sh
after_success: coveralls
5 changes: 5 additions & 0 deletions .travis/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e -u -x
pip install -r requirements.txt
pip install --no-deps .
pip check
9 changes: 2 additions & 7 deletions .travis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ if [ "$py38" = "True" ]; then
# DeprecationWarnings.
warn_args=""
else
warn_args="
-Werror
-Wignore::DeprecationWarning:site
-Wignore::PendingDeprecationWarning:nose.importer
-Wignore::DeprecationWarning:nose.importer
-Wignore::DeprecationWarning:nose.suite"
warn_args="-Werror"
fi

set -x
python $warn_args `which nosetests` --with-coverage --cover-erase --cover-package aiokatcp
pytest $warn_args --cov=aiokatcp
# The pinned version of flake8 doesn't work with Python 3.8
# (and it can't be upgraded until https://github.com/PyCQA/pyflakes/issues/445
# is fixed).
Expand Down
Empty file removed aiokatcp/tools/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[mypy]
python_version = 3.5
ignore_missing_imports = True
files = aiokatcp, examples
files = src/aiokatcp, examples, tests
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
# Avoids a warning that the default will change in pytest 6
junit_family=xunit1
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
katversion
asynctest
async-timeout
coverage
coveralls
decorator
flake8
mypy
pytest
pytest-cov
30 changes: 22 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@
#
# pip-compile requirements.in
#
async-timeout==3.0.1
asynctest==0.13.0
async-timeout==3.0.1 # via -r requirements.in
asynctest==0.13.0 # via -r requirements.in
attrs==19.3.0 # via pytest
certifi==2019.11.28 # via requests
chardet==3.0.4 # via requests
coverage==4.5.4
coveralls==1.8.2
decorator==4.4.1
coverage==4.5.4 # via coveralls, pytest-cov
coveralls==1.8.2 # via -r requirements.in
decorator==4.4.1 # via -r requirements.in
docopt==0.6.2 # via coveralls
flake8==3.6.0
flake8==3.6.0 # via -r requirements.in
idna==2.8 # via requests
katversion==0.9
iniconfig==1.0.1 # via pytest
katversion==0.9 # via -r requirements.in
mccabe==0.6.1 # via flake8
more-itertools==8.4.0 # via pytest
mypy-extensions==0.4.3 # via mypy
mypy==0.750
mypy==0.750 # via -r requirements.in
packaging==20.4 # via pytest
pluggy==0.13.1 # via pytest
py==1.9.0 # via pytest
pycodestyle==2.4.0 # via flake8
pyflakes==2.0.0 # via flake8
pyparsing==2.4.7 # via packaging
pytest-cov==2.10.0 # via -r requirements.in
pytest==6.0.1 # via -r requirements.in, pytest-cov
requests==2.22.0 # via coveralls
six==1.15.0 # via packaging
toml==0.10.1 # via pytest
typed-ast==1.4.0 # via mypy
typing-extensions==3.7.4.1 # via mypy
urllib3==1.25.7 # via requests

# The following packages are considered to be unsafe in a requirements file:
# setuptools
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@

from setuptools import setup, find_packages

tests_require = ['asynctest', 'nose']
tests_require = ['asynctest', 'pytest']
docs_require = ['sphinx', 'sphinx-autodoc-typehints', 'sphinxcontrib-asyncio', 'sphinx-rtd-theme']

setup(
name='aiokatcp',
use_katversion=True,
packages=find_packages(),
packages=find_packages('src'),
package_dir={'': 'src'},
package_data={'aiokatcp': ['py.typed']},
author='Bruce Merry',
author_email='bmerry@ska.ac.za',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 1 addition & 9 deletions aiokatcp/test/test_client.py → tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
from unittest.mock import call
from typing import Tuple, Type, Pattern, Match, cast

from nose.tools import nottest, istest
import asynctest

from aiokatcp import (Client, FailReply, InvalidReply, ProtocolError, Message,
Sensor, SensorWatcher, AbstractSensorWatcher, SyncState, encode)
from .test_utils import timelimit
from test_utils import timelimit


class DummyClient(Client):
Expand All @@ -60,7 +59,6 @@ def unhandled_inform(self, msg: Message) -> None:
self.unhandled.put_nowait(msg)


@nottest
class BaseTestClient(unittest.TestCase):
async def make_server(self, loop: asyncio.AbstractEventLoop) \
-> Tuple[asyncio.AbstractServer, asyncio.Queue]:
Expand All @@ -84,7 +82,6 @@ def callback(reader, writer):


@timelimit
@nottest
class BaseTestClientAsync(BaseTestClient, asynctest.TestCase):
async def make_client(
self,
Expand Down Expand Up @@ -122,7 +119,6 @@ async def wait_connected(self) -> None:


@timelimit
@istest
class TestClient(BaseTestClientAsync):
@timelimit(1)
async def setUp(self) -> None:
Expand Down Expand Up @@ -323,7 +319,6 @@ async def test_bad_address(self) -> None:


@timelimit
@istest
class TestSensorMonitor(BaseTestClientAsync):
"""Test the sensor monitoring interface.
Expand Down Expand Up @@ -679,7 +674,6 @@ def test_state_updated(self):


@timelimit
@istest
class TestClientNoReconnect(TestClient):
@timelimit(1)
async def setUp(self) -> None:
Expand Down Expand Up @@ -726,7 +720,6 @@ async def test_connect_failed(self) -> None:


@timelimit
@istest
class TestClientNoMidSupport(BaseTestClientAsync):
@timelimit(1)
async def setUp(self) -> None:
Expand Down Expand Up @@ -760,7 +753,6 @@ async def test_concurrent(self):
self.assertEqual(result2, ([b'2'], [Message.inform('echo', b'value', b'2')]))


@istest
class TestUnclosedClient(BaseTestClient, unittest.TestCase):
async def body(self) -> None:
server, client_queue = await self.make_server(self.loop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from aiokatcp.core import Message, KatcpSyntaxError
from aiokatcp.connection import read_message, Connection
from .test_utils import timelimit
from test_utils import timelimit


class TestReadMessage(asynctest.TestCase):
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion aiokatcp/test/test_server.py → tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from aiokatcp.connection import FailReply
from aiokatcp.server import DeviceServer, RequestContext
from aiokatcp.sensor import Sensor, SensorSampler
from .test_utils import timelimit
from test_utils import timelimit


class Foo(enum.Enum):
Expand Down
File renamed without changes.

0 comments on commit 5e04267

Please sign in to comment.