From 4a20d5b9e526435a53b7cb1dc0a819299d31f040 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Sat, 16 Feb 2019 15:41:04 -0500 Subject: [PATCH] TST: use a fixed seed to have the same uniques across python versions (#25346) TST: add pytest-mock to handle mocker fixture --- ci/deps/azure-27-compat.yaml | 1 + ci/deps/azure-27-locale.yaml | 1 + ci/deps/azure-36-locale_slow.yaml | 1 + ci/deps/azure-37-locale.yaml | 1 + ci/deps/azure-37-numpydev.yaml | 1 + ci/deps/azure-macos-35.yaml | 1 + ci/deps/azure-windows-27.yaml | 1 + ci/deps/azure-windows-36.yaml | 1 + ci/deps/travis-27.yaml | 1 + ci/deps/travis-36-locale.yaml | 1 + ci/deps/travis-36-slow.yaml | 1 + ci/deps/travis-36.yaml | 1 + ci/deps/travis-37.yaml | 1 + pandas/tests/io/formats/test_console.py | 5 ++--- pandas/tests/resample/test_datetime_index.py | 8 ++++++-- 15 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ci/deps/azure-27-compat.yaml b/ci/deps/azure-27-compat.yaml index 8899e22bdf6cf..986855c464852 100644 --- a/ci/deps/azure-27-compat.yaml +++ b/ci/deps/azure-27-compat.yaml @@ -20,6 +20,7 @@ dependencies: # universal - pytest - pytest-xdist + - pytest-mock - pip: - html5lib==1.0b2 - beautifulsoup4==4.2.1 diff --git a/ci/deps/azure-27-locale.yaml b/ci/deps/azure-27-locale.yaml index 0846ef5e8264e..f73079ecbe3d2 100644 --- a/ci/deps/azure-27-locale.yaml +++ b/ci/deps/azure-27-locale.yaml @@ -22,6 +22,7 @@ dependencies: # universal - pytest - pytest-xdist + - pytest-mock - hypothesis>=3.58.0 - pip: - html5lib==1.0b2 diff --git a/ci/deps/azure-36-locale_slow.yaml b/ci/deps/azure-36-locale_slow.yaml index c7d2334623501..6b8d38fd25082 100644 --- a/ci/deps/azure-36-locale_slow.yaml +++ b/ci/deps/azure-36-locale_slow.yaml @@ -28,6 +28,7 @@ dependencies: # universal - pytest - pytest-xdist + - pytest-mock - moto - pip: - hypothesis>=3.58.0 diff --git a/ci/deps/azure-37-locale.yaml b/ci/deps/azure-37-locale.yaml index b5a05c49b8083..569b71dae003b 100644 --- a/ci/deps/azure-37-locale.yaml +++ b/ci/deps/azure-37-locale.yaml @@ -27,6 +27,7 @@ dependencies: # universal - pytest - pytest-xdist + - pytest-mock - pip: - hypothesis>=3.58.0 - moto # latest moto in conda-forge fails with 3.7, move to conda dependencies when this is fixed diff --git a/ci/deps/azure-37-numpydev.yaml b/ci/deps/azure-37-numpydev.yaml index 99ae228f25de3..a37be124cc546 100644 --- a/ci/deps/azure-37-numpydev.yaml +++ b/ci/deps/azure-37-numpydev.yaml @@ -8,6 +8,7 @@ dependencies: # universal - pytest - pytest-xdist + - pytest-mock - hypothesis>=3.58.0 - pip: - "git+git://github.com/dateutil/dateutil.git" diff --git a/ci/deps/azure-macos-35.yaml b/ci/deps/azure-macos-35.yaml index 58abbabce3d86..d1fe926744ecd 100644 --- a/ci/deps/azure-macos-35.yaml +++ b/ci/deps/azure-macos-35.yaml @@ -24,6 +24,7 @@ dependencies: # universal - pytest - pytest-xdist + - pytest-mock - pip: - python-dateutil==2.5.3 - hypothesis>=3.58.0 diff --git a/ci/deps/azure-windows-27.yaml b/ci/deps/azure-windows-27.yaml index b1533b071fa74..74faeed83c387 100644 --- a/ci/deps/azure-windows-27.yaml +++ b/ci/deps/azure-windows-27.yaml @@ -27,5 +27,6 @@ dependencies: - cython>=0.28.2 - pytest - pytest-xdist + - pytest-mock - moto - hypothesis>=3.58.0 diff --git a/ci/deps/azure-windows-36.yaml b/ci/deps/azure-windows-36.yaml index 7b132a134c44e..94d67b3d37788 100644 --- a/ci/deps/azure-windows-36.yaml +++ b/ci/deps/azure-windows-36.yaml @@ -25,4 +25,5 @@ dependencies: - cython>=0.28.2 - pytest - pytest-xdist + - pytest-mock - hypothesis>=3.58.0 diff --git a/ci/deps/travis-27.yaml b/ci/deps/travis-27.yaml index 2624797b24fa1..4915c003bce4e 100644 --- a/ci/deps/travis-27.yaml +++ b/ci/deps/travis-27.yaml @@ -41,6 +41,7 @@ dependencies: # universal - pytest - pytest-xdist + - pytest-mock - moto==1.3.4 - hypothesis>=3.58.0 - pip: diff --git a/ci/deps/travis-36-locale.yaml b/ci/deps/travis-36-locale.yaml index 2b38465c04512..2a7692f10752c 100644 --- a/ci/deps/travis-36-locale.yaml +++ b/ci/deps/travis-36-locale.yaml @@ -30,6 +30,7 @@ dependencies: # universal - pytest - pytest-xdist + - pytest-mock - moto - pip: - hypothesis>=3.58.0 diff --git a/ci/deps/travis-36-slow.yaml b/ci/deps/travis-36-slow.yaml index a6ffdb95e5e7c..7934d179c8618 100644 --- a/ci/deps/travis-36-slow.yaml +++ b/ci/deps/travis-36-slow.yaml @@ -27,5 +27,6 @@ dependencies: # universal - pytest - pytest-xdist + - pytest-mock - moto - hypothesis>=3.58.0 diff --git a/ci/deps/travis-36.yaml b/ci/deps/travis-36.yaml index 74db888d588f4..857c3fadfdaeb 100644 --- a/ci/deps/travis-36.yaml +++ b/ci/deps/travis-36.yaml @@ -36,6 +36,7 @@ dependencies: - pytest - pytest-xdist - pytest-cov + - pytest-mock - hypothesis>=3.58.0 - pip: - brotlipy diff --git a/ci/deps/travis-37.yaml b/ci/deps/travis-37.yaml index c503124d8cd26..125750191de7d 100644 --- a/ci/deps/travis-37.yaml +++ b/ci/deps/travis-37.yaml @@ -14,6 +14,7 @@ dependencies: - pytz - pytest - pytest-xdist + - pytest-mock - hypothesis>=3.58.0 - s3fs - pip: diff --git a/pandas/tests/io/formats/test_console.py b/pandas/tests/io/formats/test_console.py index 45c5e982c1c48..a3e0e195f4864 100644 --- a/pandas/tests/io/formats/test_console.py +++ b/pandas/tests/io/formats/test_console.py @@ -78,13 +78,12 @@ def test_detect_console_encoding_fallback_to_default(monkeypatch, std, locale): @pytest.mark.parametrize("size", ['', ['']]) -def test_terminal_unknown_dimensions(monkeypatch, size): - mock = pytest.importorskip("unittest.mock") +def test_terminal_unknown_dimensions(monkeypatch, size, mocker): def communicate(*args, **kwargs): return size - monkeypatch.setattr('subprocess.Popen', mock.Mock()) + monkeypatch.setattr('subprocess.Popen', mocker.Mock()) monkeypatch.setattr('subprocess.Popen.return_value.returncode', None) monkeypatch.setattr( 'subprocess.Popen.return_value.communicate', communicate) diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index ceccb48194f85..71b100401ec21 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -1160,9 +1160,13 @@ def test_resample_nunique_with_date_gap(): @pytest.mark.parametrize('k', [10, 100, 1000]) def test_resample_group_info(n, k): # GH10914 + + # use a fixed seed to always have the same uniques + prng = np.random.RandomState(1234) + dr = date_range(start='2015-08-27', periods=n // 10, freq='T') - ts = Series(np.random.randint(0, n // k, n).astype('int64'), - index=np.random.choice(dr, n)) + ts = Series(prng.randint(0, n // k, n).astype('int64'), + index=prng.choice(dr, n)) left = ts.resample('30T').nunique() ix = date_range(start=ts.index.min(), end=ts.index.max(),