Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run pytest on GitHub Actions #197

Merged
merged 8 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run test

on:
push:
branches:
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: requirements-dev.txt
- name: Install dependencies
run: python -m pip install -r requirements-dev.txt
- name: Run tests
run: pytest --cov=fluent
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
pytest-cov
msgpack
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()
51 changes: 21 additions & 30 deletions tests/test_asynchandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
from tests import mockserver


def get_logger(name, level=logging.INFO):
logger = logging.getLogger(name)
logger.setLevel(level)
return logger


class TestHandler(unittest.TestCase):
def setUp(self):
super(TestHandler, self).setUp()
Expand All @@ -40,8 +46,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info({
Expand All @@ -63,8 +68,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '%(name)s',
Expand All @@ -86,8 +90,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '{name}',
Expand All @@ -109,8 +112,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '${name}',
Expand All @@ -131,8 +133,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '%(name)s',
Expand All @@ -147,8 +148,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '%(name)s',
Expand All @@ -172,8 +172,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info('{"key": "hello world!", "param": "value"}')
Expand All @@ -186,8 +185,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info('hello %s', 'world')
Expand All @@ -200,8 +198,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info('hello world, %s', 'you!')
Expand All @@ -214,8 +211,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info("1")
Expand All @@ -227,8 +223,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info(42)
Expand All @@ -240,8 +235,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info({42: 'root'})
Expand All @@ -254,8 +248,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
try:
Expand Down Expand Up @@ -297,8 +290,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info({'cnt': 1, 'from': 'userA', 'to': 'userB'})
Expand Down Expand Up @@ -359,8 +351,7 @@ 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')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)

Expand Down
5 changes: 3 additions & 2 deletions 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 # teach pytest this is not test class.


class TestEvent(unittest.TestCase):
Expand All @@ -18,7 +19,7 @@ def tearDown(self):
from fluent.sender import _set_global_sender
sender.close()
_set_global_sender(None)

def test_logging(self):
# XXX: This tests succeeds even if the fluentd connection failed
# send event with tag app.follow
Expand Down
Loading