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

Add pytest for unit testing #103

Merged
merged 14 commits into from
Feb 14, 2021
Merged

Add pytest for unit testing #103

merged 14 commits into from
Feb 14, 2021

Conversation

JCZuurmond
Copy link
Contributor

@JCZuurmond JCZuurmond commented Feb 6, 2021

This PR adds pytest for unit testing.

I tried to follow the dbt setup as much as possible. They have a unit test folder with unit tests. I followed the pytest best practice to mimick the package structure as well.

It is a little awkward since SQL tests and python tests are combined. The set-up expects the usually pytest directory structure in the test/unit folder - while the convention is to put those in the tests/ folder.

@mikaelene
Copy link
Collaborator

We had a discussion about testing the different ways for connection. Is this to support that? I guess that we need to clarify what is what with regards to the dbt package tests. Have the other adaptors anything like this?

@JCZuurmond
Copy link
Contributor Author

JCZuurmond commented Feb 8, 2021

yes, this indeed is intended for testing the different ways for connection. I want to use it for #100. And more generally it can be used for testing the python code.

dbt and dbt-spark have such a test/unit folder for python testing. I added subfolders to organize the test in the usual pytest way.

@swanderz : Could you have a look to see if the CI will run the python unit tests.

@dataders
Copy link
Collaborator

dataders commented Feb 8, 2021

@JCZuurmond looking like we're in the same boat as before w.r.t getting CI working from your fork. i just changed some settings, can you try pushing a new commit to see if my tweaks fixed things?

@JCZuurmond
Copy link
Contributor Author

the CI ran, the checks only show integration-sqlserver

@JCZuurmond
Copy link
Contributor Author

CI passes!

tox.ini Show resolved Hide resolved
@dataders
Copy link
Collaborator

@JCZuurmond this PR is much appreciated. I'm certainly a python testing and packaging newbie, so help in this area is great. I had originally assumed that the test/unit/ dir of dbt-spark was for testing the Python classes and functions, but it looks as if there's some integration testing in there as well?

I think we're lucky that with the connection-sqlserver and connection-azuresql CircleCI jobs, we cover most of the of the connection profile differences without having to roll our own pytest suite. My original thought is that this PR would serve so we could write unit tests for the python functions you've added, namely:

  • convert_bytes_to_mswindows_byte_string
  • convert_access_token_to_mswindows_byte_string
  • get_cli_access_token, and
  • get_sp_access_token.

But I'm unsure how the last two could be unit tests without also being integration tests... 🤷
That said this PR is all about setting the stage for future unit tests.

I want to use it for #100. And more generally it can be used for testing the python code.

as for this... I have no idea why there is only one check running instead of four.

the CI ran, the checks only show integration-sqlserver

a few asks -- can you add:

  1. pull from master and add a changelog entry?
  2. code formatting check for black @mikaelene's partial to it over flake8

@JCZuurmond
Copy link
Contributor Author

@swanderz : I can shoot in a first PR to for the unit tests. I was thinking to do some mocking to test the azure login methods.

  1. I have added a changelog entry
  2. I would do that in a different PR. Maybe recommendation would be to go for WIP: Python conventions #73 and use pre-commit. But seeing that dbt does not use pre-commit, I am ok with not usin it.

This PR is ok to be merged in my opinion!

@JCZuurmond JCZuurmond mentioned this pull request Feb 11, 2021
@dataders dataders force-pushed the add-pytest branch 2 times, most recently from dcd3160 to af1a384 Compare February 14, 2021 00:07
@dataders
Copy link
Collaborator

as for this... I have no idea why there is only one check running instead of four.

the CI ran, the checks only show integration-sqlserver

So deleted a blank line and now all the jobs run...

More importantly, everything is passing now! LGTM

@dataders dataders merged commit ebf779a into dbt-msft:master Feb 14, 2021
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.

3 participants