Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Migrate test runner to py.test #569

Merged
merged 2 commits into from
Aug 10, 2016

Conversation

pferate
Copy link
Contributor

@pferate pferate commented Jul 26, 2016

Maintainer of pytest_gae needs to merge open PR and push to PyPI.
In the mean time, get code directly from GitHub mirror.

@theacodes
Copy link
Contributor

We can probably just rip off the App Engine stuff from here into a conftest.py for the appengine things.

(it's not a lot of code)

define these on set up.
"""
global Signer
global Verifier

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@pferate
Copy link
Contributor Author

pferate commented Jul 26, 2016

@jonparrott Should we worry about populating the conftest.py file now? Or should we wait until we start moving everything to fixtures (phase 3)?

@pferate pferate force-pushed the pytest_runner branch 5 times, most recently from 2e5b8cb to 16ce742 Compare July 27, 2016 15:53
@pferate
Copy link
Contributor Author

pferate commented Jul 27, 2016

There is a bug in the 0.9 release of flake8-import-order (released yesterday) that is causing the flake8 test to incorrectly fail.

I've already created an issue for it.

@theacodes
Copy link
Contributor

@pferate if we need app engine stuff to work (which we do) we might as well populate conftest.py just for that. You only need a subset of the stuff in the example I linked.

@pferate
Copy link
Contributor Author

pferate commented Jul 27, 2016

I copied the code from App Engine file you linked. I moved the imports within setup_sdk_imports to within try/except blocks, so that the tests don't fail outside of App Engine.

I just added the fixture code for this PR to pytest_configure().

These will be expanded more when we transition the tests here to fixtures.

pass


def import_appengine_config():

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@theacodes theacodes added this to the 4.0.0 milestone Jul 27, 2016
@theacodes
Copy link
Contributor

Please don't merge this until after the 3.0.0 release. I'll remove the label when it's safe.

@theacodes
Copy link
Contributor

theacodes commented Jul 28, 2016

v3.0.0 is released so this can now be considered for merging.

@pferate
Copy link
Contributor Author

pferate commented Jul 28, 2016

Should there be a 4.x or Dev branch, so that they can be kept separate from 3.x updates?

@theacodes
Copy link
Contributor

Should there be a 4.x or Dev branch, so that they can be kept separate from 3.x updates?

I don't think so, but @nathanielmanistaatgoogle is welcome to overrule that.


# Fixes timezone and other os-level items.
import google.appengine.tools.os_compat
(google.appengine.tools.os_compat)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@pferate
Copy link
Contributor Author

pferate commented Aug 8, 2016

Rebased onto master.

Thanks for the help @jonparrott!

Return True to skip collection. Skips App Engine tests when --gae-sdk
is not specified.
"""
if 'contrib/appengine' in str(path):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@nathanielmanistaatgoogle
Copy link
Contributor

Looks mostly good; just that one comment.

@pferate
Copy link
Contributor Author

pferate commented Aug 9, 2016

@jonparrott, with us moving the app engine tests into their own directory, should we move the app engine modules into their own directory as well?

Another coupled set of files are contrib/gce and contrib/_metadata.

@theacodes
Copy link
Contributor

with us moving the app engine tests into their own directory, should we move the app engine modules into their own directory as well?

I don't think so. There's no hard and fast rule that tests must be organized exactly as their module-under-test. I think defaulting to that but making exceptions where it makes testing easier (like we did here) makes sense. Practicality beats purity.

set_up_gae_environment(config.getoption('gae_sdk'))


def pytest_ignore_collect(path, config):

This comment was marked as spam.

@pferate
Copy link
Contributor Author

pferate commented Aug 9, 2016

@nathanielmanistaatgoogle: PR updated, PTAL.


def pytest_ignore_collect(path, config):
"""Direct py.test to skip App Engine tests when --gae-sdk is not specified.

This comment was marked as spam.

This comment was marked as spam.

@nathanielmanistaatgoogle
Copy link
Contributor

One last tweak; sorry.

@pferate
Copy link
Contributor Author

pferate commented Aug 9, 2016

PR updated. @nathanielmanistaatgoogle PTAL.

@nathanielmanistaatgoogle
Copy link
Contributor

What's with that test failure?

Is it desired that this go in as two commits? (No pushing in either direction; just want to confirm.)

@pferate
Copy link
Contributor Author

pferate commented Aug 9, 2016

Looks like it may be related to #590. This is what is in my Travis logs:

# Travis ships with an old version of PyPy, so install at least version 2.6.
if [[ "${TOX_ENV}" == "pypy" ]]; then
    git clone https://github.com/yyuu/pyenv.git ${HOME}/.pyenv
    ${HOME}/.pyenv/bin/pyenv install pypy-2.6.0
fi
fatal: destination path '/home/travis/.pyenv' already exists and is not an empty directory.

In my repo, pypy passed the first time, but failed when I reran the test.

As for the commits, one was a merged PR from @jonparrott helping me sort out some of the GAE tests, so I didn't want to lose his work within mine. Functionally, they could be squashed.

@theacodes
Copy link
Contributor

The pypy failure is my fault. We probably just need to check for the non-existence of {$HOME}/.pyenv before doing the git clone.

We can do it in this PR or I can send a separate one.

@nathanielmanistaatgoogle
Copy link
Contributor

Separate pull request with the fix in isolation, please.

@theacodes
Copy link
Contributor

@pferate It's fixed, rebase and try again?

Migrating test runner from `unittest2`/`nose` to `pytest`.
The pytest runner is also compatible with both unittest and nose tests.
Some of the benefits of PyTest include:
    * using plain asserts
    * function-based fixtures instead of setUp and tearDown
    * no strange camelCase methods
@pferate pferate force-pushed the pytest_runner branch 3 times, most recently from fe201ff to e80dd38 Compare August 9, 2016 21:36
@pferate
Copy link
Contributor Author

pferate commented Aug 9, 2016

@jonparrott Rebased and waiting on Travis.

One weird thing that I've been seeing recently is py33 tests have been failing in my fork on Travis, but have been passing on the main repo. They also pass when I run them on my local system.

The 2 linked Travis jobs are from the same commit from yesterday. It looks like my fork is collecting the django tests (it shouldn't) and the main repo correctly skips them. Before I dig much further, do you have any idea of what's going on?

As long as it passes on the main repo, it doesn't really matter; but this seems strange.

@nathanielmanistaatgoogle
Copy link
Contributor

@pferate: are you waiting for answers from @jonparrott before this gets merged?

(I am completely fine with the pull request content and metadata; feel free to merge when conversation is again concluded.)

@pferate
Copy link
Contributor Author

pferate commented Aug 9, 2016

No need to wait. I just had some weird, unique test results that I'm trying to figure out on my end.

@nathanielmanistaatgoogle nathanielmanistaatgoogle merged commit f774a66 into googleapis:master Aug 10, 2016
@pferate pferate deleted the pytest_runner branch August 10, 2016 17:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants