From 231f3b4760fe11e1094fa8d5bd24dd2d56475d3d Mon Sep 17 00:00:00 2001 From: Witek Bedyk Date: Tue, 26 Nov 2019 10:18:59 +0100 Subject: [PATCH] Enable running unit tests in py37 environment Until now no unit tests have been executed in py37 environment. This change fixes tox configuration to enable running these tests. It also fixes two unit tests to handle PEP479 being enabled for all code in Python 3.7 [1, 2]. [1] https://docs.python.org/3/whatsnew/3.7.html#changes-in-python-behavior [2] https://stackoverflow.com/questions/51700960/runtimeerror-generator-raised-stopiteration-every-time-i-try-to-run-app Change-Id: I7fcf30d848efb8dc4cc6ca19056868aa6127cf60 --- monasca_common/tests/test_confluent_kafka.py | 8 ++++++-- monasca_common/tests/test_kafka.py | 6 +++++- tox.ini | 9 +++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/monasca_common/tests/test_confluent_kafka.py b/monasca_common/tests/test_confluent_kafka.py index 8bc60dec..b23dd539 100644 --- a/monasca_common/tests/test_confluent_kafka.py +++ b/monasca_common/tests/test_confluent_kafka.py @@ -162,8 +162,12 @@ class TestConfluentKafkaConsumer(base.BaseTestCase): m.set_value("message{}".format(i)) messages.append(m) self.consumer._consumer.poll.side_effect = messages - for index, message in enumerate(self.consumer): - self.assertEqual(message, messages[index]) + try: + for index, message in enumerate(self.consumer): + self.assertEqual(message, messages[index]) + except RuntimeError as re: + if 'generator raised StopIteration' in str(re): + pass @mock.patch('confluent_kafka.Message') @mock.patch('confluent_kafka.KafkaError') diff --git a/monasca_common/tests/test_kafka.py b/monasca_common/tests/test_kafka.py index 925a0db7..73dcad4d 100644 --- a/monasca_common/tests/test_kafka.py +++ b/monasca_common/tests/test_kafka.py @@ -173,6 +173,10 @@ class TestKafkaConsumer(base.BaseTestCase): mock_set_partitioner.return_value.acquired = True mock_set_partitioner.return_value.__iter__.return_value = [1] - list(self.monasca_kafka_consumer) + try: + list(self.monasca_kafka_consumer) + except RuntimeError as re: + if 'generator raised StopIteration' in str(re): + pass self.consumer.seek.assert_called_once_with(0, 0) diff --git a/tox.ini b/tox.ini index 6ac74ea2..2f365a87 100644 --- a/tox.ini +++ b/tox.ini @@ -34,6 +34,15 @@ commands = {[testenv]commands} stestr run --blacklist-file {env:BLACKLIST_FILE} {posargs} +[testenv:py37] +basepython = python3.7 +setenv = + {[testenv]setenv} + BLACKLIST_FILE={toxinidir}/test-blacklist-py3.txt +commands = + {[testenv]commands} + stestr run --blacklist-file {env:BLACKLIST_FILE} {posargs} + [testenv:cover] setenv = PYTHON=coverage run --source monasca_common --parallel-mode