conftest.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. """
  3. tests.integration.conftest
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Integration tests PyTest configuration/fixtures
  6. """
  7. # pylint: disable=unused-argument,redefined-outer-name
  8. # Import Python libs
  9. from __future__ import absolute_import, unicode_literals
  10. import logging
  11. from collections import OrderedDict
  12. # Import 3rd-party libs
  13. import psutil
  14. import pytest
  15. log = logging.getLogger(__name__)
  16. @pytest.fixture(scope="package", autouse=True)
  17. def default_session_daemons(
  18. request,
  19. log_server,
  20. session_salt_master,
  21. session_salt_minion,
  22. session_secondary_salt_minion,
  23. ):
  24. request.session.stats_processes.update(
  25. OrderedDict(
  26. (
  27. ("Salt Master", psutil.Process(session_salt_master.pid)),
  28. ("Salt Minion", psutil.Process(session_salt_minion.pid)),
  29. ("Salt Sub Minion", psutil.Process(session_secondary_salt_minion.pid)),
  30. )
  31. ).items()
  32. )
  33. # Run tests
  34. yield
  35. # Stop daemons now(they would be stopped at the end of the test run session
  36. for daemon in (
  37. session_secondary_salt_minion,
  38. session_salt_minion,
  39. session_salt_master,
  40. ):
  41. try:
  42. daemon.terminate()
  43. except Exception as exc: # pylint: disable=broad-except
  44. log.warning("Failed to terminate daemon: %s", daemon.__class__.__name__)