MaterialEditor_Atom_ExpectsTestTimeout.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. """
  6. class Tests:
  7. material_editor_test_timed_out = ( # This test result is pytest.mark.xfail.
  8. "AtomToolsSingleTest class didn't time out and passed (it should fail from timing out).",
  9. "P0: AtomToolsSingleTest timed out before the test could complete (expected failure)."
  10. )
  11. def MaterialEditor_TestsTimeout_TimeoutFailure():
  12. """
  13. Summary:
  14. Tests that the MaterialEditor can fail from timed out tests on the AtomToolsSingleTest class objects.
  15. Expected Behavior:
  16. The MaterialEditor test fails due to time out from the timeout value in AtomToolsSingleTest class.
  17. Test Steps:
  18. 1) Delay the start of the auto-success check so that timeout values in AtomToolsSingleTest take hold.
  19. 2) Create callback function to wait for the delay so that the test times out before success is reached.
  20. 3) Auto-pass the test now since it should time out before this point.
  21. 4) Look for errors and asserts.
  22. :return: None
  23. """
  24. import time
  25. import Atom.atom_utils.atom_tools_utils as atom_tools_utils
  26. from editor_python_test_tools.utils import Report, Tracer, TestHelper
  27. with Tracer() as error_tracer:
  28. # 1. Delay the start of the auto-success check so that timeout values in AtomToolsSingleTest take hold.
  29. start_time = time.time() + 12
  30. # 2. Create callback function to wait for the delay so that the test times out before success is reached.
  31. def time_check():
  32. if time.time() > start_time:
  33. return True
  34. return False
  35. atom_tools_utils.wait_for_condition(time_check(), 15)
  36. # 3. Auto-pass the test now since it should time out before this point.
  37. Report.success(Tests.material_editor_test_timed_out)
  38. # 4. Look for errors and asserts.
  39. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  40. for error_info in error_tracer.errors:
  41. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  42. for assert_info in error_tracer.asserts:
  43. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  44. if __name__ == "__main__":
  45. from editor_python_test_tools.utils import Report
  46. Report.start_test(MaterialEditor_TestsTimeout_TimeoutFailure)