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

test: Remove 'src' from pytest test testpaths to allow for non-editable install in CI #1467

Merged
merged 18 commits into from
Oct 19, 2021

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented May 18, 2021

Description

Resolves #1456

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* Remove 'src' from the pytest testpaths in pyproject.toml
* Remove '--editable' pip install option from CI
* Use 'pytest' over 'python -m pytest' to avoid adding the current directory to sys.path
   - c.f. https://docs.pytest.org/en/latest/how-to/usage.html#calling-pytest-through-python-m-pytest
* Split doctest test coverage into separate run and report
* For backend consistency, specify a backend in README examples
   - Also truncate prints of CLs values to finite precision
* Split pytest addopts across multiple lines in pyproject.toml for readability

@matthewfeickert matthewfeickert added tests pytest CI CI systems, GitHub Actions fix A bug fix labels May 18, 2021
@matthewfeickert matthewfeickert self-assigned this May 18, 2021
@codecov
Copy link

codecov bot commented May 18, 2021

Codecov Report

Merging #1467 (e865224) into master (be5ae65) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1467   +/-   ##
=======================================
  Coverage   98.04%   98.04%           
=======================================
  Files          63       63           
  Lines        4145     4145           
  Branches      572      572           
=======================================
  Hits         4064     4064           
  Misses         48       48           
  Partials       33       33           
Flag Coverage Δ
contrib 24.89% <ø> (ø)
doctest 61.01% <ø> (?)
unittests 96.33% <ø> (-1.50%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be5ae65...e865224. Read the comment docs.

@matthewfeickert matthewfeickert marked this pull request as draft May 18, 2021 02:50
pyproject.toml Outdated Show resolved Hide resolved
@matthewfeickert matthewfeickert force-pushed the tests/remove-src-from-testpaths branch from 0df71e7 to 4cccfc9 Compare October 19, 2021 06:14
@matthewfeickert matthewfeickert marked this pull request as ready for review October 19, 2021 07:22
@matthewfeickert matthewfeickert changed the title fix: Remove 'src' from pytest test testpaths to allow for non-editable install in CI test: Remove 'src' from pytest test testpaths to allow for non-editable install in CI Oct 19, 2021
@matthewfeickert
Copy link
Member Author

Relevant RTD build page: https://pyhf--1467.org.readthedocs.build/en/1467/#hello-world

@henryiii
Copy link
Member

Changes look fine, I only disagree with this line in the changelog:

Use 'pytest' over 'python -m pytest' to avoid adding the current directory to sys.path. Having
the cwd in sys.path invalidates some of the benefits of using a src directory structure for
testing.

You can't invalidate the benefits of a src directory with this; this is the benefit of a src directory. There's no way to import pyhf from src/pyhf by putting the current directory into the path. You would have to add "src" to the PYTHONPATH / sys.path.

Also, if you do coverage testing, I think you'll need an editable install (which is fine, you should be able to do either one).

@matthewfeickert
Copy link
Member Author

matthewfeickert commented Oct 19, 2021

You can't invalidate the benefits of a src directory with this; this is the benefit of a src directory. There's no way to import pyhf from src/pyhf by putting the current directory into the path. You would have to add "src" to the PYTHONPATH / sys.path.

Yeah, you're right. Edited. Thanks for the catch.

Also, if you do coverage testing, I think you'll need an editable install (which is fine, you should be able to do either one).

Can you elaborate a bit on this? The below seems to be working for generating a coverage file and reporting

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip setuptools wheel
        python -m pip install --upgrade .[test]

...

    - name: Test with pytest
      run: |
        pytest -r sx --ignore tests/benchmarks/ --ignore tests/contrib --ignore tests/test_notebooks.py

    - name: Report core project coverage with Codecov
      if: github.event_name != 'schedule' && matrix.python-version == 3.9 && matrix.os == 'ubuntu-latest'
      uses: codecov/codecov-action@v2
      with:
        files: ./coverage.xml
        flags: unittests

Why do we need an editable install? (I could be missing something very obvious)

Copy link
Contributor

@kratsg kratsg left a comment

Choose a reason for hiding this comment

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

Some other unrelated changes made their way into this PR as well.

README.rst Show resolved Hide resolved
README.rst Show resolved Hide resolved
@henryiii
Copy link
Member

I thought that coverage was picky about the paths that it reports, that is, if it's reporting src/pyhf/... it's happy and not if it's <random long location>/pyhf/.... Could be wrong though, I get CodeCov and coveralls muddled.

@henryiii
Copy link
Member

CodeCov seems to be happy. :)

@matthewfeickert
Copy link
Member Author

I thought that coverage was picky about the paths that it reports, that is, if it's reporting src/pyhf/... it's happy and not if it's <random long location>/pyhf/.... Could be wrong though, I get CodeCov and coveralls muddled.

CodeCov seems to be happy. :)

Ah okay, thanks for the clarification. Agreed, as CodeCov seems happy then I think we're good here. Thanks for taking time to look this over though @henryiii — always appreciate your time and input!

@kratsg kratsg merged commit 8a3dc6b into master Oct 19, 2021
@kratsg kratsg deleted the tests/remove-src-from-testpaths branch October 19, 2021 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI CI systems, GitHub Actions fix A bug fix tests pytest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pytest fails for source installs that don't use pip install --editable .
4 participants