Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyTest Inner Workings Overhaul #377

Merged
merged 2 commits into from
Aug 20, 2019
Merged

PyTest Inner Workings Overhaul #377

merged 2 commits into from
Aug 20, 2019

Conversation

Lnaden
Copy link
Collaborator

@Lnaden Lnaden commented Aug 20, 2019

Description

This PR makes an overhaul to the nuances of our PyTest framework.

  • In order to ship around the testing configuration (the contents of conftest.py), this PR ports all of those features to the testing.py file which is now treated as a first class PyTest Plugin.
  • The pytest11 entry point for the testing.py file has been added to the setup.py file so it will be detected automatically by any installed PyTest, allowing transferring of the --runslow and --runexamples CLI flags into PyTest on its own.
    • This also enables the ability to access these flags anywhere
  • Due to the removal of the pytest.config global in the Version 5+ of PyTest, I had to rework how some of our mark functions behave. Instead of writing our own decorators, I instead am using the PyTest recommended method of pytest_collection_modifyitems, an example of which can be found here. I have also based this off the implementation this from Dask Distributed Fix pytest.config deprecation warning dask/distributed#2677.
  • Due to the previous change, the mark_slow and mark_example decorators are no more. We now just use pytest.mark.slow and pytest.mark.example respectively. This change has been propagated through the tests.
  • I fixed a bug in the test_visualization where the _has_plotly flag was always being set to True.
  • I have tested this with both PyTest 5 and PyTest 4.6.3

And finally, all of this, was so we could install QCFractal and run pytest --pyargs qcfractal from anywhere and still have access to the optional --runslow flag (and it solved a PyTest 5 deprecation)

Status

  • Changelog updated
  • Ready to go

This PR makes an overhaul to the nuances of our PyTest framework.

* In order to ship around the testing configuration (the contents of
  `conftest.py`), this PR ports all of those features to the `testing.py`
  file which is now treated as a first class PyTest Plugin.
* The `pytest11` entry point for the `testing.py` file has been added
  to the `setup.py` file so it will be detected automatically by any
  installed PyTest, allowing transferring of the `--runslow` and
  `--runexamples` CLI flags into PyTest on its own.
    * This also enables the ability to access these flags anywhere
* Due to the removal of the [pytest.config global](https://docs.pytest.org/en/latest/deprecations.html#pytest-config-global) in the Version 5+ of PyTest, I had to
  rework how some of our `mark` functions behave. Instead of writing
  our own decorators, I instead am using the PyTest recommended method
  of `pytest_collection_modifyitems`, an example of which can be found
  [here](https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option).
  I have also based this off the implementation this from Dask Distributed
  dask/distributed#2677.
* Due to the previous change, the `mark_slow` and `mark_example`
  decorators are no more. We now just use `pytest.mark.slow` and
  `pytest.mark.example` respectively. This change has been propagated
  through the tests.
* I fixed a bug in the `test_visualization` where the `_has_plotly` flag
  was always being set to `True`.
* I have tested this with both PyTest 5 and PyTest 4.6.3

And finally, all of this, was so we could install QCFractal and run
`pytest --pyargs qcfractal` from anywhere and still have access to the
optional `--runslow` flag (and it solved a PyTest 5 deprecation)
@Lnaden Lnaden added Bug Code execution error Documentation Unclear or incorrect documentation Testing Testing bug or enhancement labels Aug 20, 2019
@Lnaden Lnaden requested a review from dgasmith August 20, 2019 17:59
@codecov
Copy link

codecov bot commented Aug 20, 2019

Codecov Report

Merging #377 into master will increase coverage by 0.04%.
The diff coverage is 72.72%.

Copy link
Contributor

@dgasmith dgasmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, merge when ready!

@@ -8,6 +8,7 @@
from . import portal

try:
import plotly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah....

"flag to run.")


def pytest_unconfigure(config):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you have found the magic incantation. Was it on the bottom of a snake?

Copy link
Collaborator Author

@Lnaden Lnaden Aug 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In certain interpretations, it could be. Moreover it required me to sacrifice a Lantern of Diogenes which could only be used in the daytime to summon a bridge across Cocytus to find it.

It also might be left over from the conftest.py and I don't know if it actually does anything.

ONE OR MORE OF THOSE TWO STATEMENTS IS TRUE.

@@ -201,7 +201,7 @@ def test_service_torsiondrive_option_energy_upper_limit(torsiondrive_fixture):
assert pytest.approx(0.0007991274441437338, abs=1e-6) == final_energies[(-60, )]


@mark_slow
@pytest.mark.slow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see this approach. Ok, should work!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also extend it with the 3 functions in the plugin in the future.

@Lnaden Lnaden merged commit 1693b06 into MolSSI:master Aug 20, 2019
@Lnaden Lnaden deleted the pytest5 branch August 20, 2019 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Code execution error Documentation Unclear or incorrect documentation Testing Testing bug or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants