From 6d2b876b5e705a1799e38dbcaaec6a0115e7939b Mon Sep 17 00:00:00 2001 From: Naman Priyadarshi Date: Thu, 16 Nov 2023 17:12:01 +0530 Subject: [PATCH] add comment explaining conftest.py --- benchexec/tablegenerator/conftest.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/benchexec/tablegenerator/conftest.py b/benchexec/tablegenerator/conftest.py index 9ac4f7d59..145e67319 100644 --- a/benchexec/tablegenerator/conftest.py +++ b/benchexec/tablegenerator/conftest.py @@ -5,14 +5,17 @@ # # SPDX-License-Identifier: Apache-2.0 +# The following code is intended for use in pytest sessions and ensures consistent rounding behavior during tests. +# It sets the rounding mode to ROUND_HALF_UP for both the DefaultContext and the local context at the start of the session. +# This helps maintain reproducibility in test results by avoiding discrepancies in rounding behavior across different environments or configurations. +# The use of pytest_sessionstart hook from `conftest.py` ensures that this setup is applied globally at the beginning of each test session. + import decimal -# Store the original rounding values original_default_rounding = decimal.DefaultContext.rounding original_local_rounding = decimal.getcontext().rounding def pytest_sessionstart(session): - # Set both DefaultContext and local context rounding to ROUND_HALF_UP at the beginning of the test session decimal.DefaultContext.rounding = decimal.ROUND_HALF_UP decimal.getcontext().rounding = decimal.ROUND_HALF_UP