Skip to content

Commit 7f8ca4d

Browse files
committed
use option_context to set options in test
1 parent b69af4d commit 7f8ca4d

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

pandas/tests/tslibs/test_parsing.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111
import pytest
1212

13-
from pandas._config import set_option
13+
from pandas import option_context
1414

1515
from pandas._libs.tslibs import (
1616
parsing,
@@ -428,34 +428,35 @@ def test_hypothesis_delimited_date(
428428
@pytest.mark.parametrize("input", ["21-01-01", "01-01-21"])
429429
@pytest.mark.parametrize("dayfirst", [True, False])
430430
def test_parse_datetime_string_with_reso_dayfirst(dayfirst, input):
431-
set_option("display.date_dayfirst", dayfirst)
432-
except_out_dateutil, result = _helper_hypothesis_delimited_date(
433-
parsing.parse_datetime_string_with_reso, input
434-
)
435-
except_in_dateutil, expected = _helper_hypothesis_delimited_date(
436-
du_parse,
437-
input,
438-
default=datetime(1, 1, 1),
439-
dayfirst=dayfirst,
440-
yearfirst=False,
441-
)
442-
assert except_out_dateutil == except_in_dateutil
443-
assert result[0] == expected
431+
with option_context("display.date_dayfirst", dayfirst):
432+
except_out_dateutil, result = _helper_hypothesis_delimited_date(
433+
parsing.parse_datetime_string_with_reso, input
434+
)
435+
436+
except_in_dateutil, expected = _helper_hypothesis_delimited_date(
437+
du_parse,
438+
input,
439+
default=datetime(1, 1, 1),
440+
dayfirst=dayfirst,
441+
yearfirst=False,
442+
)
443+
assert except_out_dateutil == except_in_dateutil
444+
assert result[0] == expected
444445

445446

446447
@pytest.mark.parametrize("input", ["21-01-01", "01-01-21"])
447448
@pytest.mark.parametrize("yearfirst", [True, False])
448449
def test_parse_datetime_string_with_reso_yearfirst(yearfirst, input):
449-
set_option("display.date_yearfirst", yearfirst)
450-
except_out_dateutil, result = _helper_hypothesis_delimited_date(
451-
parsing.parse_datetime_string_with_reso, input
452-
)
453-
except_in_dateutil, expected = _helper_hypothesis_delimited_date(
454-
du_parse,
455-
input,
456-
default=datetime(1, 1, 1),
457-
dayfirst=False,
458-
yearfirst=yearfirst,
459-
)
460-
assert except_out_dateutil == except_in_dateutil
461-
assert result[0] == expected
450+
with option_context("display.date_yearfirst", yearfirst):
451+
except_out_dateutil, result = _helper_hypothesis_delimited_date(
452+
parsing.parse_datetime_string_with_reso, input
453+
)
454+
except_in_dateutil, expected = _helper_hypothesis_delimited_date(
455+
du_parse,
456+
input,
457+
default=datetime(1, 1, 1),
458+
dayfirst=False,
459+
yearfirst=yearfirst,
460+
)
461+
assert except_out_dateutil == except_in_dateutil
462+
assert result[0] == expected

0 commit comments

Comments
 (0)