Skip to content

MAINT: Configure hypothesis in np.test() for determinism, use of global tmpdir#16879

Merged
mattip merged 1 commit intonumpy:masterfrom
Zac-HD:isolate-hypothesis-config
Aug 2, 2020
Merged

MAINT: Configure hypothesis in np.test() for determinism, use of global tmpdir#16879
mattip merged 1 commit intonumpy:masterfrom
Zac-HD:isolate-hypothesis-config

Conversation

@Zac-HD
Copy link
Contributor

@Zac-HD Zac-HD commented Jul 16, 2020

This PR fixes #16859, by ensuring that np.test() is deterministic, and that any files written by np.test() (or invoking pytest directly) go to the same global temporary directory instead of the current working directory.

CC @mattip @rgommers @marload from the other PR, if you want to try this out.

@mattip
Copy link
Member

mattip commented Jul 16, 2020

Nice. As for pytest, it seems the .pytest directory is being created by pytest cache. There is a note that it can be disabled like any plugin, something like python -m pytest -p no:cacheprovider. I wonder if we can add that to np.test() by default

This will still create a .hypothesis directory when run from a git checkout via python runtests.py ..., correct? So we still need to add .hypothesis to .gitignore

@Zac-HD
Copy link
Contributor Author

Zac-HD commented Jul 16, 2020

This will still create a .hypothesis directory when run from a git checkout via python runtests.py ..., correct? So we still need to add .hypothesis to .gitignore

If python runtests.py ... avoids importing or executing numpy.conftest, yes it will... and we'd miss all the other Hypothesis config too in that case.

Otherwise, we should have the same setup as the other ways to run tests which redirects everything to tempfile.gettempdir() + "/.hypothesis regardless of working directory. No harm in adding .hypothesis/ to gitignore though, and I can imagine odd scenarios where it would be useful.

@charris charris changed the title Configure hypothesis in np.test() for determinism, use of global tmpdir MAINT: Configure hypothesis in np.test() for determinism, use of global tmpdir Jul 16, 2020
@mattip
Copy link
Member

mattip commented Jul 22, 2020

On the one hand, with this PR I no longer have a .hypothesis directory in ./build/testenv/lib/python3.7/site-packages/.hypothesis. However, I see a warning with pytest=5.4.3

/home/matti/miniconda3/envs/numpy/lib/python3.7/site-packages/_pytest/config/__init__.py:935
  /home/matti/miniconda3/envs/numpy/lib/python3.7/site-packages/_pytest/config/__init__.py:935: PytestAssertRewriteWarning: Module already imported so cannot be rewritten: hypothesis
    self._mark_plugins_for_rewrite(hook)

-- Docs: https://docs.pytest.org/en/latest/warnings.html

@Zac-HD Zac-HD force-pushed the isolate-hypothesis-config branch from f297625 to 3d74fab Compare July 23, 2020 04:23
@Zac-HD
Copy link
Contributor Author

Zac-HD commented Jul 23, 2020

@mattip - I've moved the import hypothesis to after import pytest in the __call__ method, which I'm pretty sure will fix that warning.

@mattip mattip merged commit 0f12338 into numpy:master Aug 2, 2020
@mattip
Copy link
Member

mattip commented Aug 2, 2020

Thanks @Zac-HD

@Zac-HD Zac-HD deleted the isolate-hypothesis-config branch August 2, 2020 13:32
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Aug 4, 2020
@mattip
Copy link
Member

mattip commented Aug 9, 2020

I've moved the import hypothesis to after import pytest in the __call__ method

@Zac-HD The warning still appears

@Zac-HD
Copy link
Contributor Author

Zac-HD commented Aug 9, 2020

Maybe hypothesis is being imported somehow before the __call__ method is called? I don't know what's happening through, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants