Skip to content

Commit

Permalink
take logger in use
Browse files Browse the repository at this point in the history
  • Loading branch information
jupe committed Sep 2, 2024
1 parent 758b19b commit 908f2a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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

0 comments on commit 908f2a9

Please sign in to comment.