Skip to content

Commit

Permalink
add comment explaining conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Naman Priyadarshi authored and Naman Priyadarshi committed Nov 16, 2023
1 parent d73d101 commit 6d2b876
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions benchexec/tablegenerator/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6d2b876

Please sign in to comment.