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

Tests should be self-contained and repeatable #259

Closed
carljm opened this issue Apr 16, 2011 · 8 comments
Closed

Tests should be self-contained and repeatable #259

carljm opened this issue Apr 16, 2011 · 8 comments
Labels
C: tests Testing and related things type: maintenance Related to Development and Maintenance Processes

Comments

@carljm
Copy link
Contributor

carljm commented Apr 16, 2011

Tests that depend on external things (PyPI, github, bitbucket, launchpad) are brittle and prone to failure. Our current caching strategy for those external dependencies helps with the speed problem (some; not as much as one would hope), but makes the fragility even worse - it introduces an extra layer of complexity and of things that might change from one test run to the next (i.e. some broken test corrupting the cache causes the next cached run to fail). These are all real problems that wasted my time during the Py3k porting work.

I want to convert all of pip's tests to be all self-contained all the time and fully repeatable - no external dependencies. That means our tests create any repositories that they need locally as part of test setup, and we use hg serve, bzr serve, git-web etc if needed to simulate fetching across the network. Similarly for PyPI.

We could leave in place a test script that does some actual tests with remote repos and PyPI, that wouldn't be run as part of the normal test suite or by CI, but could be used as a real-world sanity check.

@pnasrat
Copy link
Contributor

pnasrat commented Apr 20, 2011

See also Issue #181

@pnasrat
Copy link
Contributor

pnasrat commented Apr 21, 2011

I wonder if we should annotate all the expensive test using nose plubing attrib - eg:

from nose.plugins.attrib import attr
@attr(speed='slow')
def test_download_intahwebs():
   pass

This would helpfully mark all the tests we need to migrate and the difference between testing styles would be easily discoverable to new contributors.

@pnasrat
Copy link
Contributor

pnasrat commented Apr 21, 2011

Just to give some basic measurements

nosetests -s test_basic
....................S..............
----------------------------------------------------------------------
Ran 35 tests in 61.515s

@carljm
Copy link
Contributor Author

carljm commented Apr 21, 2011

Annotating using that plugin seems fine to me.

In particular, I'd like to annotate (and then eliminate) the ones that access external network resources. Slowness is related, but not the same - simply installing stuff can be slow enough to make end-to-end functional tests pretty slow even if they never access the network (this is largely why the network-caching stuff from last summer wasn't nearly as successful in reducing test runtimes as we'd hoped). But yeah - annotating slow tests is fine too.

@msabramo
Copy link
Contributor

msabramo commented Mar 6, 2015

Now we'd have to use pytest markers instead of nose ones, but that's a small change.

I remember now that pytest-httpbin forks a process with httpbin, a simple Flask app, so I don't see why we couldn't do the same to create local mocks of PyPI, github, bitbucket, launchpad, ...

@msabramo
Copy link
Contributor

msabramo commented Mar 6, 2015

But we'd still need to have versions that hit the real PyPI, GitHub, etc. and run them every now and then, to make sure that we're not testing against mocks that no longer reflect reality.

@msabramo
Copy link
Contributor

A bunch of PRs were just merged that address some of this at least for tests/functional/test_freeze.py:

@pradyunsg
Copy link
Member

pip's test suite is certainly repeatable now. We don't have complete network isolation, but I reckon that's OK. Closing this out on the basis that having tests depend on the network is OK; as long as it's clearly reflected.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C: tests Testing and related things type: maintenance Related to Development and Maintenance Processes
Projects
None yet
Development

No branches or pull requests

4 participants