Skip to content

Better test structure #139

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

Merged
merged 23 commits into from
Mar 8, 2018
Merged

Better test structure #139

merged 23 commits into from
Mar 8, 2018

Conversation

max-sixty
Copy link
Contributor

Move towards more pytest idioms, reduce amount of code, reduce branching. This is a starter; still lots to do.

But can merge if ppl agree and keep making small improvments

@codecov-io
Copy link

codecov-io commented Mar 3, 2018

Codecov Report

Merging #139 into master will decrease coverage by 46.21%.
The diff coverage is 41.55%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #139       +/-   ##
===========================================
- Coverage   75.75%   29.53%   -46.22%     
===========================================
  Files           8        8               
  Lines        1633     1534       -99     
===========================================
- Hits         1237      453      -784     
- Misses        396     1081      +685
Impacted Files Coverage Δ
pandas_gbq/tests/test_gbq.py 23.21% <41.55%> (-60.2%) ⬇️
pandas_gbq/gbq.py 20.56% <0%> (-56.24%) ⬇️
pandas_gbq/_load.py 62.5% <0%> (-35%) ⬇️

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 1674760...ce6eebc. Read the comment docs.

@max-sixty
Copy link
Contributor Author

More improvements made, at a good place to merge now

@max-sixty
Copy link
Contributor Author

@tswast @parthea Could you review? Let's get these in and then I'll merge them into the others.

Copy link
Collaborator

@tswast tswast left a comment

Choose a reason for hiding this comment

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

I like it! I have some worries this will make the tests take longer than we really need, though. Comments inline.

@@ -179,39 +172,80 @@ def test_generate_bq_schema_deprecated():
gbq.generate_bq_schema(df)


class TestGBQConnectorIntegrationWithLocalUserAccountAuth(object):
@pytest.fixture(params=['local', 'service_path', 'service_creds'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Woah. TIL about parameterized fixtures. Cool stuff.


def setup_method(self, method):
@pytest.fixture(autouse=True)
def setup(self, project, credentials):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since queries can be pretty long-running, I don't think we really want to use all 3+ credentials types here.


def test_should_read_as_user_account(self):
_skip_local_auth_if_in_travis_env()
def test_should_read(project, credentials):
Copy link
Collaborator

Choose a reason for hiding this comment

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

As opposed to my comment below, I do like this test using all three credentials types.

I think it's good to verify that with a speedy query like this one.


def setup_method(self, method):
@pytest.fixture(autouse=True, scope='function')
def setup(self, project, credentials):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto. I don't think we want all tests running with all credentials types, but we should have 1 test that does.

@max-sixty
Copy link
Contributor Author

max-sixty commented Mar 7, 2018

I have some worries this will make the tests take longer

Generally only one of the sets of tests will run, because for the other auth types they'll be skipped.
https://github.com/pydata/pandas-gbq/pull/139/files#diff-a348bd9d754cdc9d2ed5ec75a9626bcdR186

Indeed - this is no worse than the existing setup, where we had a bunch of copy & pasted code, but only one of the versions would run because the others would be skipped. Here we can also run tests using user auth, but that's the only growth in available tests.

In a future version, we could pass explicit options from the command line on which auth type(s) should be used, rather than auto-skipping based on the environment. That would also have the advantage that the test suite won't pass if no authentication is available.

But I don't think we need to couple those changes - this is strictly an improvement from the existing version - or is there something I'm missing?

Copy link
Collaborator

@tswast tswast left a comment

Choose a reason for hiding this comment

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

I agree that this is definitely an improvement.

I'm not convinced that the tests will only run once in general, as my understanding of _get_private_key_contents() is that it will always read the file at _get_private_key_path(), so in that case both will run using service account keys.

If that's the case and we decide that the tests are taking too long, we can always go back an refactor.

@tswast
Copy link
Collaborator

tswast commented Mar 7, 2018

@maxim-lian Did this pass on your Travis?

@stickler-ci
Copy link

I couldn't find a .stickler.yml file in this repository. I can make one for you, or you can create one by following the documentation.

@max-sixty
Copy link
Contributor Author

so in that case both will run using service account keys.

That's a good point. Should we skip one in Travis?

Checking here, they do take about twice as long

They do pass

@max-sixty
Copy link
Contributor Author

I've skipped one in Travis. Would be better to make the travis run command pass a command line which defined this to a parameterized test suite, but this is fine for the moment IMO

@tswast tswast merged commit 672b357 into googleapis:master Mar 8, 2018
@max-sixty max-sixty deleted the better-pytest branch March 8, 2018 00:15
@tswast tswast mentioned this pull request Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants