asset_processor_fixture.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. A fixture for using the Asset Processor, this will stop the asset processor after every test via
  6. the teardown. Using the fixture at class level will stop the asset processor after the suite completes.
  7. Using the fixture at test level will stop asset processor after the test completes. Calling this fixture as a test argument will still run the teardown to stop the Asset Processor.
  8. """
  9. # Import Builtins
  10. import pytest
  11. import logging
  12. # Import LyTestTools
  13. import ly_test_tools.o3de.asset_processor as asset_processor_commands
  14. import ly_test_tools.o3de.asset_processor_utils
  15. logger = logging.getLogger(__name__)
  16. @pytest.fixture
  17. def asset_processor(request: pytest.fixture, workspace: pytest.fixture) -> asset_processor_commands.AssetProcessor:
  18. """
  19. Sets up usage of the asset proc
  20. :param request:
  21. :return: ly_test_tools.03de.asset_processor.AssetProcessor
  22. """
  23. # Initialize the Asset Processor
  24. ap = asset_processor_commands.AssetProcessor(workspace)
  25. # Custom teardown method for this fixture
  26. def teardown():
  27. logger.info("Running asset_processor_fixture teardown to stop the AP")
  28. ap.stop()
  29. request.addfinalizer(teardown)
  30. for n in ly_test_tools.o3de.asset_processor_utils.processList:
  31. assert not ly_test_tools.o3de.asset_processor_utils.check_ap_running(n), f"{n} process did not shutdown correctly."
  32. return ap