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

Avoid using requests unnecessarily in tests #3670

Merged

Conversation

jayvdb
Copy link
Contributor

@jayvdb jayvdb commented Apr 3, 2019

This replaces requests with tablib in tests where using requests
in a de-vendored environment causes the tests to fail unnecessarily.

Continuation of #3644

Thank you for contributing to Pipenv!

The issue

What is the thing you want to fix? Is it associated with an issue on GitHub? Please mention it.

Always consider opening an issue first to describe your problem, so we can discuss what is the best way to amend it. Note that if you do not describe the goal of this change or link to a related issue, the maintainers may close the PR without further review.

If your pull request makes a non-insignificant change to Pipenv, such as the user interface or intended functionality, please file a PEEP.

https://github.com/pypa/pipenv/blob/master/peeps/PEEP-000.md

The fix

How does this pull request fix your problem? Did you consider any alternatives? Why is this the best solution, in your opinion?

The checklist

  • Associated issue
  • A news fragment in the news/ directory to describe this fix with the extension .bugfix, .feature, .behavior, .doc. .vendor. or .trivial (this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.

@jayvdb
Copy link
Contributor Author

jayvdb commented Apr 3, 2019

I have at least another test which should have this type of change, so I'll add it here shortly.

@jayvdb
Copy link
Contributor Author

jayvdb commented Apr 3, 2019

Note in test_uninstall.py I have kept one requests uninstall, renamed to test_uninstall_requests, so that anyone devendoring will still have a failure to contend with, and a note there to indicate the cause is quite simply the de-vendoring.

At a latter stage, we need to better understand just how much of pipenv fails when de-vendoring. Probably after the next release, when all distros re-do their de-vendoring, we can focus their attention on those failures which they like to skip and hope for the best.

I can think of a few basic tests which could be added, such as installing specific versions of requests and testing whether the requested version is visible inside the venv. My guess is that also fails. But that and other tests should be a separate set of analysis and separate PR.

@jayvdb
Copy link
Contributor Author

jayvdb commented Apr 3, 2019

I believe this is all of the changes needed to resolve this issue.

The only other test failures I have are listed at #3630 , and I am fairly confident they are not the same problem as this issue.

Im happy to revise this patch heavily based on feedback. I probably havent made the best choices of alternative packages, and there are probably changes needed to match the local style, etc.

# Ensure the --pypi-mirror parameter hasn't altered the Pipfile or Pipfile.lock sources
assert len(p.pipfile["source"]) == 1
assert len(p.lockfile["_meta"]["sources"]) == 1
assert "https://pypi.org/simple" == p.pipfile["source"][0]["url"]
assert "https://pypi.org/simple" == p.lockfile["_meta"]["sources"][0]["url"]

c = p.pipenv("run python -m requests.help")
c = p.pipenv("run python -m django --version")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note Django was used here to continue using the run python -m .. syntax, and there are not many packages in tests/pypi/ that have a __main__. We could add another lighter package with a __main__ to the pypi archive .

Or this could be changed to using run python -c 'import x' which is almost as good, with a slightly less understandable error if the test fails. But I think 99% of the people likely to encounter an error here are going to understand the backtrace caused by import x failing.

@@ -119,16 +119,16 @@ def test_install_without_dev(PipenvInstance, pypi):
six = "*"

[dev-packages]
pytz = "*"
tablib = "*"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This replacing of pytz with tablib is a slightly different from the others, which are replacing requests.

pytz is not a dependency of pipenv, however it is a dependency of the test runner, so it is also added in PYTHONPATH in order to get the builds working in rpmbuild.

I can workaround this by creating a special venv with only the real dependencies of pipenv, and using that in PYTHONPATH. But that is quite a bit more effort, and I doubt many distro maintainers would accept a much more complicated testing rig just so this one test passes - they would likely prefer to just mark this test as a skip.

Note I do not expect pipenv devs to always be avoiding requests and other dependencies in these tests. It would be nice if they were avoided, especially requests, but it is not possible to predict in advance all of the dependencies, especially all of the test rig dependencies.

I think the responsibility of creating fixup patches like this one falls on the de-vendor-ers after each release.

Also we should also be working on creating a job which blocks internet access so that the 'internet' marker becomes 100% reliable here -- so that de-vendor-ers dont feel that some of the failures they see might be due to 'no internet', and hopefully they investigate any failures more before shipping broken package updates to users.

@jayvdb jayvdb force-pushed the test_include_editable_packages-not-requests branch from 39248c2 to 8604d58 Compare May 8, 2019 12:28
@techalchemy
Copy link
Member

oops I triggered azure's abuse detection :o

Sorry this took so long but there were a lot of issues to untangle, once I can run the tests here I will address the specific comments. Generally speaking I have no issues swapping out one library for another and if you have implementations for moving things offline I am more than happy to merge them.

@techalchemy techalchemy added Category: Tests Relates to tests. PR: awaiting-review The PR related to this issue is awaiting review by a maintainer. Priority: Medium This item is medium priority and will be resolved whenever possible. Status: In Progress This item is in progress. Type: Maintenance 🚧 This issue pertains to maintenance of pipenv itself. Type: Vendored Dependencies This issue affects vendored dependencies within pipenv. labels May 20, 2019
@jayvdb
Copy link
Contributor Author

jayvdb commented May 20, 2019

Glad to see pipenv has green builds again. I'll keep a close eye on this PR and happy to change it as needed.

If I have spare time after this, my focus will be to create new versions of these tests which are written so they fail when de-vendoring and directly demonstrate the unsolved problems resulting from de-vendoring, with a pytest mark so they are easy to skip as a group.

@frostming
Copy link
Contributor

@jayvdb Please merge and we are good to go.

@jayvdb
Copy link
Contributor Author

jayvdb commented Jul 10, 2019

ok, on it.

jayvdb added 6 commits July 11, 2019 13:33
This replaces requests with tablib in test_include_editable_packages
as in a de-vendored environment the locking fails with requests.

Continuation of pypa#3644
These tests fail when using requests in a de-vendored installation
because requests is part of the pre-installed image.

tablib has fewer constraints on its dependencies, however its
dependency tree is complicated enough to approximately test
the same functionality, and allows the graph tests to pass
even when de-vendored.
Using requests in tests fails when pipenv is de-vendored.
In this test, using any package with multiple versions
in the local pypi data will suffice to show the functionality
does work, but not with requests, or any devendored package.

Continuation of pypa#3644
pytz exists in the build environment, which will typically
be added to the PYTHONPATH when running the tests in rpmbuild.
The alternative is to create a virtualenv containing only the
pipenv dependencies, which is cumbersome to do when devendoring.
As the pytz library here is not critical to the logic of the
test method, replace it with tablib to reduce unintentionally
errors when packaging.

Continuation of pypa#3644
@jayvdb jayvdb force-pushed the test_include_editable_packages-not-requests branch from daf69c6 to 2f5150a Compare July 11, 2019 06:35
@frostming
Copy link
Contributor

Thanks for the work, merging.

@frostming frostming merged commit 9c51b34 into pypa:master Jul 13, 2019
@techalchemy
Copy link
Member

Hey thanks again for all the effort on this, I know this was a lot of work

@techalchemy
Copy link
Member

@jayvdb if you have any notes on your decisionmaking process it might be helpful to begin updating our contributing guidelines to factor in your process into how we decide what to use on future tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Tests Relates to tests. PR: awaiting-review The PR related to this issue is awaiting review by a maintainer. Priority: Medium This item is medium priority and will be resolved whenever possible. Status: In Progress This item is in progress. Type: Maintenance 🚧 This issue pertains to maintenance of pipenv itself. Type: Vendored Dependencies This issue affects vendored dependencies within pipenv.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants