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

Running and bundling tests with namespace packages #2225

Closed
theacodes opened this issue Aug 30, 2016 · 13 comments
Closed

Running and bundling tests with namespace packages #2225

theacodes opened this issue Aug 30, 2016 · 13 comments
Assignees

Comments

@theacodes
Copy link
Contributor

(Context: PR #2223 towards #1978)

PR #2223's tests can't run because nose will place cwd into sys.path when running tests. This means import google.cloud will import ./google/cloud instead of {env}/lib/python{x}.{y}/site-packages/google/cloud. This will clobber all other google namespace packages. There is an long-open issue here, note that Nose has been largely abandoned.

There are a two of ways we could resolve this, and maybe we should do both:

  1. Move the tests to their own top-level package as described in the py.test docs.
  2. Switch to py.test's test runner, pytest. It's fully compatible with nose/unittest style tests. py.test appropriately deals with namespace/installed packages.

On switching to py.test

  1. py.test has slightly different arguments than nose, notably for coverage. This is pretty easy to deal with.
  2. Switching to py.test will either mean we have to switch to having the tests in a separate package or that we have to switch from tox to nox. The reason is that py.test will try to import relative to the test modules it discovers, and so will try to import the module-under-test from the current working directory, but will actually give an error because the same module is present in site-packages. This can be resolved by either moving the tests to a separate package or installing the package in "editable" mode with pip install -e. Unfortunately, tox doesn't easily allow you to change the command used to install the package under test. There might be a few hacks (turning off sdist and manually installing the package). Nox however gives you complete control over the creation, here's a simple config that works for gcloud-python.

On moving the tests to a test package

The were originally concerns about having the tests in a separate top-level tests package because we didn't want it to get installed with gcloud-python but we did want to distribute the tests. This should be resolvable by telling find_packages() to skip tests and including tests in manifest.in. This means that wheels and sdists will contain the tests folder for downstream packagers, but pip will not install the tests package into site-packages.

@tseaver
Copy link
Contributor

tseaver commented Aug 31, 2016

In https://github.com/GoogleCloudPlatform/google-cloud-python-happybase, I moved the google package into a non-package src directory to resolve this issue. I would prefer that to either of these alternatives.

@dhermes
Copy link
Contributor

dhermes commented Aug 31, 2016

@tseaver The fact that the nose project is dead is a signal we should move to py.test. As for moving unit tests, I don't care where they live. I just sent #2227 to move them into a directory called unit_tests so in some sense it'll be more obvious where they live than it currently is.

@theacodes
Copy link
Contributor Author

theacodes commented Aug 31, 2016

@tseaver I'm not super thrilled about src/google and using package_dir, but I'm willing to be fine with it as a temporary solution to get the namespace change unblocked.

@dhermes
Copy link
Contributor

dhermes commented Aug 31, 2016

@jonparrott I've already got the test move done and after that the py.test change should be straightforward

@theacodes
Copy link
Contributor Author

👍 , though I'd love to have @tseaver on board. :)

@tseaver
Copy link
Contributor

tseaver commented Aug 31, 2016

The src/ prefix directory is in common use among other namespace-package projects (the zope.* packages all use it).

@dhermes
Copy link
Contributor

dhermes commented Aug 31, 2016

@tseaver I'm not sure how src/ fixes the issue?

@theacodes
Copy link
Contributor Author

@dhermes it side-steps the issue of:

tests can't run because nose will place cwd into sys.path

By putting them under src doing import google.cloud won't look at src/google/cloud.

@dhermes
Copy link
Contributor

dhermes commented Sep 1, 2016

I just tried that in #2223 and it made the failures worse (tox -e py27 still breaks with google namesapce and now .tox/py27/bin/nosetests also broken)

@tseaver
Copy link
Contributor

tseaver commented Sep 1, 2016

@dhermes Check what I did in google-cloud-python-happybase: the tests are all happy running from inside src, and the namespace package is correct.

@dhermes
Copy link
Contributor

dhermes commented Sep 1, 2016

@tseaver Thanks for the pointer. My ambiguous "I just tried that" above meant that I copied what you had done there. Unclear on where the failure is.

@dhermes
Copy link
Contributor

dhermes commented Sep 6, 2016

@jonparrott This is "resolved"

@dhermes dhermes closed this as completed Sep 6, 2016
@theacodes
Copy link
Contributor Author

👍

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

No branches or pull requests

3 participants