__init__.py 2.6 KB

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