__init__.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import logging
  2. from datetime import datetime
  3. import pathlib
  4. import sys
  5. import os
  6. from pathlib import Path
  7. from pluggy import HookspecMarker, HookimplMarker, PluginManager
  8. from baangt.base.PathManagement import ManagedPaths
  9. hook_spec = HookspecMarker("baangt")
  10. hook_impl = HookimplMarker("baangt")
  11. plugin_manager = PluginManager("baangt")
  12. from baangt.hookSpecs import baangtHookSpec
  13. plugin_manager.add_hookspecs(baangtHookSpec)
  14. from baangt.base.TestRun.hookImpls import TestRunHookImpl
  15. from baangt.base.BrowserHandling.hookImpls import BrowserDriverHookImpl
  16. from baangt.base.Timing.hookImpls import TimingHookImpl
  17. from baangt.base.ExportResults.hookImpls import \
  18. (ExportResultsHookImpl, ExcelSheetHelperFunctionsHookImpl, ExportTimingHookImpl)
  19. plugin_manager.register(plugin=TestRunHookImpl())
  20. plugin_manager.register(plugin=BrowserDriverHookImpl())
  21. plugin_manager.register(plugin=TimingHookImpl())
  22. plugin_manager.register(plugin=ExportResultsHookImpl())
  23. plugin_manager.register(plugin=ExcelSheetHelperFunctionsHookImpl())
  24. plugin_manager.register(plugin=ExportTimingHookImpl())
  25. # fixme: Parameter für Logfile should include stage and browser()
  26. managedPaths = ManagedPaths()
  27. logFilename:pathlib.Path = Path(managedPaths.getLogfilePath())
  28. pathlib.Path(logFilename).mkdir(parents=True, exist_ok=True)
  29. logFilename = logFilename.joinpath(datetime.now().strftime("%Y%m%d_%H%M%S") + '.log')
  30. print(f"Logfile used: {logFilename}")
  31. # Bit more advanced logging
  32. logger = logging.getLogger('pyC')
  33. logger.setLevel(logging.DEBUG)
  34. # create file handler which logs even debug messages
  35. fileHandler = logging.FileHandler(logFilename, encoding ="UTF-8")
  36. fileHandler.setLevel(level=logging.DEBUG)
  37. # create console handler with a higher log level
  38. channelHandler = logging.StreamHandler()
  39. channelHandler.setLevel(logging.INFO)
  40. # create formatter and add it to the handlers
  41. formatter = logging.Formatter('%(asctime)s _ %(levelname)s _ %(module)s _ %(funcName)s : %(message)s')
  42. channelHandler.setFormatter(formatter)
  43. fileHandler.setFormatter(formatter)
  44. # add the handlers to logger
  45. logger.addHandler(channelHandler)
  46. logger.addHandler(fileHandler)
  47. # Some general debug info:
  48. logger.debug(f"Value of sys._MEIPASS {getattr(sys, '_MEIPASS', 'None')}")
  49. logger.debug(f"Value of __file__: {__file__}")
  50. logger.debug(f"Value of sys.executable: {sys.executable}")
  51. logger.debug(f"Value of sys.argv[0]: {sys.argv[0]}")
  52. logger.debug(f"Value of sys.path: {sys.path}")
  53. logger.debug(f"Value of os.path: {os.path}")
  54. logger.debug(f"Value of os.getcwd(): {os.getcwd()}")
  55. logger.debug(f"Value of Path.cwd(): {Path.cwd()}")
  56. if hasattr(sys, 'frozen') and hasattr(sys, '_MEIPASS'):
  57. logger.debug('running in a PyInstaller bundle')
  58. else:
  59. logger.debug('running in a normal Python process')