From 7b9c51c9d6138d930f85cbd5a477c51784c4cd3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Haziza?= Date: Sun, 1 Apr 2018 13:55:31 +0200 Subject: [PATCH] output test names --- tests/conftest.py | 10 ++++++++++ tests/{keyserver.py => test_keyserver.py} | 4 +++- tests/{openpgp.py => test_openpgp.py} | 17 +++++++++++------ tox.ini | 3 ++- 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 tests/conftest.py rename tests/{keyserver.py => test_keyserver.py} (93%) rename tests/{openpgp.py => test_openpgp.py} (85%) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..cd9118c1 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,10 @@ +# Configure tests to print the docstrings (and class+function names if no docstrings) + +def pytest_itemcollected(item): + par = item.parent.obj + node = item.obj + # First line only + prefix = par.__doc__.split('\n',1)[0].strip() if par.__doc__ else par.__class__.__name__ + suffix = node.__doc__.split('\n',1)[0].strip() if node.__doc__ else node.__name__ + if prefix or suffix: + item._nodeid = ' | '.join((prefix, suffix)) diff --git a/tests/keyserver.py b/tests/test_keyserver.py similarity index 93% rename from tests/keyserver.py rename to tests/test_keyserver.py index 6db311f9..a7711ab3 100644 --- a/tests/keyserver.py +++ b/tests/test_keyserver.py @@ -6,7 +6,9 @@ class KeyserverTestCase(AioHTTPTestCase): - """Testing keyserver by importing the routes and mocking the innerworkings.""" + """KeyServer + + Testing keyserver by importing the routes and mocking the innerworkings.""" async def get_application(self): """Retrieve the routes to a mock server.""" diff --git a/tests/openpgp.py b/tests/test_openpgp.py similarity index 85% rename from tests/openpgp.py rename to tests/test_openpgp.py index 81e26a21..d71880bd 100644 --- a/tests/openpgp.py +++ b/tests/test_openpgp.py @@ -1,3 +1,6 @@ +'''OpenPGP + +Testing that the openpgp utilities with a given set of public/private keys and a simple file to decrypt''' import unittest import io @@ -16,7 +19,9 @@ def fetch_private_key(key_id): return make_key(data) def test_session_key(): - '''Check if the session key is correctly decrypted''' + '''Retrieve the session key + + Get the session key (Decrypt with PGP Private Key and passphrase).''' name = cipher = session_key = None output = io.BytesIO() infile = io.BytesIO(bytes.fromhex(openpgp_data.ENC_FILE)) @@ -29,7 +34,7 @@ def test_session_key(): assert( session_key.hex().upper() == openpgp_data.SESSION_KEY ) def test_decryption(): - '''Decrypt an encrypted file and match with its original''' + '''Decrypt an encrypted file and match with its original.''' name = cipher = session_key = None output = io.BytesIO() infile = io.BytesIO(bytes.fromhex(openpgp_data.ENC_FILE)) @@ -44,7 +49,7 @@ def test_decryption(): assert( output.getvalue() == openpgp_data.ORG_FILE ) def test_keyid_for_pubkey(): - '''Get the keyID from armored pub key''' + '''Get the keyID from armored pub key.''' infile = io.BytesIO(openpgp_data.PGP_PUBKEY.encode()) key_id = None for packet in iter_packets(unarmor(infile)): @@ -56,7 +61,7 @@ def test_keyid_for_pubkey(): assert( key_id == openpgp_data.KEY_ID ) def test_keyid_for_pubkey_bin(): - '''Get the keyID from binary pub key''' + '''Get the keyID from binary pub key.''' infile = io.BytesIO(bytes.fromhex(openpgp_data.PGP_PUBKEY_BIN)) key_id = None for packet in iter_packets(infile): @@ -68,7 +73,7 @@ def test_keyid_for_pubkey_bin(): assert( key_id == openpgp_data.KEY_ID ) def test_keyid_for_privkey(): - '''Get the keyID from armored priv key''' + '''Get the keyID from armored priv key.''' infile = io.BytesIO(openpgp_data.PGP_PRIVKEY.encode()) key_id, data = None, None for packet in iter_packets(unarmor(infile)): @@ -80,7 +85,7 @@ def test_keyid_for_privkey(): assert( key_id == openpgp_data.KEY_ID ) def test_keyid_for_privkey_bin(): - '''Get the keyID from binary priv key''' + '''Get the keyID from binary priv key.''' infile = io.BytesIO(bytes.fromhex(openpgp_data.PGP_PRIVKEY_BIN)) key_id, data = None, None for packet in iter_packets(infile): diff --git a/tox.ini b/tox.ini index e1d8f9d9..a367d1a1 100644 --- a/tox.ini +++ b/tox.ini @@ -16,4 +16,5 @@ deps = flake8 deps = -rrequirements.txt -rtests/requirements.txt -commands = pytest +# Stop after first failure +commands = pytest -x tests/