Skip to content

Commit

Permalink
fix tests on pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Feb 27, 2024
1 parent 2a6fb7b commit 0e4d7d9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 40 deletions.
3 changes: 0 additions & 3 deletions tests/mockserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,3 @@ def close(self):
pass

self.join()

def __del__(self):
self.close()
17 changes: 2 additions & 15 deletions tests/test_asynchandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def setUp(self):
super(TestHandler, self).setUp()
self._server = mockserver.MockRecvServer('localhost')
self._port = self._server.port
logging.getLogger().setLevel(logging.INFO)

def tearDown(self):
self._server.close()
self._server = None

def get_handler_class(self):
# return fluent.handler.FluentHandler
Expand All @@ -40,7 +42,6 @@ def test_simple(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -63,7 +64,6 @@ def test_custom_fmt(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -86,7 +86,6 @@ def test_custom_fmt_with_format_style(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -109,7 +108,6 @@ def test_custom_fmt_with_template_style(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -131,7 +129,6 @@ def test_custom_field_raise_exception(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -147,7 +144,6 @@ def test_custom_field_raise_exception(self):
def test_custom_field_fill_missing_fmt_key_is_true(self):
handler = self.get_handler_class()('app.follow', port=self._port)
with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -172,7 +168,6 @@ def test_json_encoded_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -186,7 +181,6 @@ def test_unstructured_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -200,7 +194,6 @@ def test_unstructured_formatted_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -214,7 +207,6 @@ def test_number_string_simple_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -227,7 +219,6 @@ def test_non_string_simple_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -240,7 +231,6 @@ def test_non_string_dict_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -254,7 +244,6 @@ def test_exception_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand Down Expand Up @@ -297,7 +286,6 @@ def test_simple(self):
self.assertEqual(handler.sender.queue_circular, True)
self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE)

logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand Down Expand Up @@ -359,7 +347,6 @@ def custom_full_queue():
self.assertEqual(handler.sender.queue_circular, True)
self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE)

logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from tests import mockserver


class TestException(BaseException): pass
class TestException(BaseException):
__test__ = False


class TestEvent(unittest.TestCase):
Expand Down
20 changes: 2 additions & 18 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ def setUp(self):
super(TestHandler, self).setUp()
self._server = mockserver.MockRecvServer('localhost')
self._port = self._server.port
logging.getLogger().setLevel(logging.INFO)

def tearDown(self):
self._server.close()
self._server = None

def get_data(self):
return self._server.get_received()
Expand All @@ -24,7 +26,6 @@ def test_simple(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -50,7 +51,6 @@ def test_custom_fmt(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -73,7 +73,6 @@ def test_exclude_attrs(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(exclude_attrs=[])
Expand All @@ -91,7 +90,6 @@ def test_exclude_attrs_with_exclusion(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(exclude_attrs=["funcName"])
Expand All @@ -109,7 +107,6 @@ def test_exclude_attrs_with_extra(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(exclude_attrs=[])
Expand Down Expand Up @@ -138,7 +135,6 @@ def formatter(record):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt=formatter)
Expand All @@ -157,7 +153,6 @@ def test_custom_fmt_with_format_style(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -181,7 +176,6 @@ def test_custom_fmt_with_template_style(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -204,7 +198,6 @@ def test_custom_field_raise_exception(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -223,7 +216,6 @@ def test_custom_field_fill_missing_fmt_key_is_true(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
Expand All @@ -248,7 +240,6 @@ def test_json_encoded_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -265,7 +256,6 @@ def test_json_encoded_message_without_json(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter(format_json=False))
log.addHandler(handler)
Expand All @@ -282,7 +272,6 @@ def test_unstructured_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -297,7 +286,6 @@ def test_unstructured_formatted_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -312,7 +300,6 @@ def test_number_string_simple_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -326,7 +313,6 @@ def test_non_string_simple_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -340,7 +326,6 @@ def test_non_string_dict_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand All @@ -355,7 +340,6 @@ def test_exception_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
Expand Down
7 changes: 4 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ envlist = py27, py32, py33, py34, py35, py36, py37, py38
skip_missing_interpreters = True

[testenv]
deps = nose
coverage~=4.5.4
commands = python setup.py nosetests
deps =
pytest
msgpack
commands = pytest -v

0 comments on commit 0e4d7d9

Please sign in to comment.