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

take logger in use #30

Merged
merged 8 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 5 additions & 5 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ on:
pull_request:
paths-ignore:
- '**.md'

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9']
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: install deps
Expand All @@ -34,7 +34,7 @@ jobs:
# missing tests, sorry
#- name: coveralls
# if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9'
# env:
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: coveralls
- name: pylint
Expand All @@ -45,7 +45,7 @@ jobs:
run: |
pytest --opentmi localhost:3000 --opentmi_token 123 --metadata foo bar --metadata DUT_SERIAL_NUMBER 123 --metadata DUT_MODEL S5 --metadata DUT_VENDOR samsang example.py
- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: artifacts
path: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017
Copyright (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 12 additions & 4 deletions pytest_opentmi/OpenTmiReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import datetime
import uuid
import inspect
import logging
from multiprocessing.dummy import Pool as ThreadPool
# 3rd party modules
from opentmi_client import OpenTmiClient, Result
from opentmi_client.api import Dut, File, Provider, Testcase
# app modules
from . import __pytest_info__

logger = logging.getLogger(__name__)


# pylint: disable=too-many-instance-attributes
class OpenTmiReport:
Expand Down Expand Up @@ -283,7 +286,8 @@ def _link_session(self, session, result): # pylint: disable=unused-argument
def _upload_report(self, result: Result):
try:
data = self._client.post_result(result)
print(data)
logger.info(f"Uploaded {result.tcid} successfully, id: {data['id']}")
logger.debug(f"Uploaded {result.tcid} successfully, data: {data}")
self._uploaded_success += 1
except Exception: # pylint: disable=broad-except
self._uploaded_failed += 1
Expand All @@ -298,8 +302,11 @@ def _upload_reports(self, session):
[self._link_session(session, result) for result in self.results]

# pylint: disable=expression-not-assigned
[print(result.data) for result in self.results]
[print(test) for test in self.tests]
logger.info(f'Test results to be upload ({len(self.results)})')
[logger.debug(result.data) for result in self.results]

logger.info(f'Test cases to be upload ({len(self.tests)})')
[logger.debug(test) for test in self.tests]

token = self.config.getoption("opentmi_token")
pool = ThreadPool(10)
Expand All @@ -310,8 +317,9 @@ def _upload_reports(self, session):
pool.map(self._upload_report, self.results)
pool.close()
pool.join()
logger.info('All results uploaded successfully')
except Exception as error: # pylint: disable=broad-except
print(error)
logger.error(error)

@staticmethod
def _get_test_key(item):
Expand Down
4 changes: 4 additions & 0 deletions pytest_opentmi/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
pytest plugin
"""
import os
import logging
# app modules
from . import __version__
from .OpenTmiReport import OpenTmiReport

logger = logging.getLogger(__name__)


# pylint: disable=unused-argument
def pytest_report_header(config):
Expand Down Expand Up @@ -59,6 +62,7 @@ def pytest_configure(config):
# prevent opening opentmi reporter on slave nodes (xdist)
config._opentmi = OpenTmiReport(config) # pylint: disable=protected-access
config.pluginmanager.register(config._opentmi) # pylint: disable=protected-access
logger.debug(f'Opentmi reporter enabled: {host}')


def pytest_unconfigure(config):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
"Topic :: Utilities",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
],
)
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
# and then run "tox" from this directory.

[tox]
envlist = py{36,37,py3}{,-ansi2html}, linting
envlist = py{38,py3}{,-ansi2html}, linting

[testenv]
setenv = PYTHONDONTWRITEBYTECODE=1
deps =
pytest-xdist
pytest-rerunfailures
pytest-mock
py{36,37,py3}-ansi2html: ansi2html
py{38,py3}-ansi2html: ansi2html
commands = pytest -v -r a {posargs}

[testenv:linting]
Expand Down
Loading