-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Better unit tests for Helm Chart #11657
Comments
CC: @OmairK I know you wanted to know more about Kubernetes. |
I am absolutely for this. Comparing to the above proposal, it's heaven and earth. I very much dislike the current yaml based testing, they're difficult to maintain, refactor, automate, run from the IDE, debug, duplicate to write new tests etc. (unless I do not now how - maybe I just need some training). I've added a few yaml-based tests in the past and fixed a few failing ones when I added new features (like kerberos sidecar). And it was a pain. For me this is the main reason why I have not added tests to my changes to the helm chart - because I disliked the idea of being close to that part of the code. Sorry for the rant, it's not really, really bad with those yaml tests, but it is pretty close. I certainly feel subconscious " let's not go anywhere near those tests" when I think about them :). And looking at the proposal above, it is so much better. |
CC: @schnie |
This is an interesting problem. I personally lean more towards terratest than I do towards any home-bakes solution. This of course raises the question of "but is airflow a python-only project" to which my reply would be "helm is a golang-based system. You're using go templating and all major tooling around it is written in golang." @kaxil @ashb would love your thoughts as well, but especially since the helm chart is basically a separate entity from airflow itself, and that any python solution would essentially be home-baked, I'm pretty heavily for terratest. |
Snap comment without reading much of the context (sorry!): Yeah, I have no love of yaml, but I value not having to write our own test framework more. I'll read this in detail tomorrow |
@dimberman DevOps world uses Bash, Python and Golang. I think anyone who knows Helm knows the basics of Python. However, this is not true the other way around. Not everyone who knows Python also knows Go. We also don't need all Terratest features. If we have one goal - testing Helm templates, Then pytest will meet the expectations and we won't have to write a lot of our own code. It is enough to generate a template ( @ashb I don't want to write my own framework, but using pytest instead of helm-unittest. |
Yeah I am strongly with @mik-laj on that one. This has nothing to do with writing own framework. Pytest is there and we all know it well. Those tests are basically about rendering yaml files and comparing if they are what they are expected to be. We use precisely "0" other features of terratest. |
To be precise, terratest is just a library that provides a set of functions that make it easier to write tests, but it is not a full framework. You can use any framework, but the documentation recommends using Go’s built-in package testing. The module of interest for us is: So now we have discussions as to which we want to use one of the following set of tools.
I don't think we use any unique golang features (good asynchronous libraries, security, etc.) on the other hand, Python is a language valued for its simple syntax and user-friendliness. I would like to add that currently the integration tests for Helm Chart are also written in Python. What are the benefits of Golang in our case? The potential popularity with other contributors is a benefit, but I don't see them being active in the development of this Helm Chart. Rather, new features are being added by active contributors to the project who are already familiar with Python. However, if someone is not familiar with Python, writing new tests should not be a challenge for him, because Python is simpler than golang. |
(also it's a draft PR so tests will certainly fail/code quality needs clean-up but I think the basic idea will scale really well) |
Yes, in quickly skimming the issue last night on my phone I missed a lot of the context. And an alternative version that uses pytest fixtures: |
Hello, I come from #11681 (comment) . So a bit of feedback on the experience with the current setup:
Going for something a bit more custom with golang or python will enable easier "advance" tests (this chart has some very complex logic, so I have a feeling that it's going to be useful). And on Golang vs Python, I'd agree with:
I think some small "internal" python testing logic like what I can see in #11693 is nice. |
@mik-laj @FloChehab @potiuk Do you prefer the unit test style, or the pytest fixture style? #11693 and #11694 |
@ashb I prefer unittest.TestCase, but I don't have a strong opinion. Any solution that is written in Python works for me. Related discussion: https://lists.apache.org/thread.html/1e4df7d4b0cd9b2d2bb76a3336471aa85e852545dd41ada6d4e461b8%40%3Cdev.airflow.apache.org%3E |
Honestly I think my biggest complaint now is the I think pytest fixtures are powerful, but on first seeing them they are a bit "magic" I'll grant. |
+1 for assert style, I think we should fix it in all database after 2.0 - there's a tool to do that.
I think I'm ok with both - fixtures and mocking. Sometimes I prefer to use one way and in other situation I prefer the other one. In general, I think the test style is something that we should discuss after 2.0 - we didn't want to do any changes/enforcement previously because we had a looooot of changes (pre-commits, pytest, AIP-21 and more). |
I like fixtures when used with the scope module or session. When I only need to use fixtures for one test, I prefer to create simple functions instead of using fixtures/magic. |
I think I agree with all of you @ashb @turbaszek and @mik-laj :). Seems we all agree actually :) +1 asserts are better (but let's not make it consistent just yet) |
Pytest has setup/teardown equivalents too, even without fixtures https://docs.pytest.org/en/stable/xunit_setup.html#method-and-function-level-setup-teardown |
Correct. But it feels like joining the worst of both worlds. Classic unit-test setUp/tearDown are familiar and "natural" where pytest fixtures are modern and a bit less familiar. I'd rather move to fixtures rather than to pytest's setup/teardown. |
I don't have an opinion for going for the one or the other ; I am sure you'll make the good choice. |
I like both of them - @ashb and @dimberman . However, if I had to choose one PR it would be @dimberman's PR because it includes additional k8s API validation. |
Yeah Daniel has taken it further than I have - I was just creating a prototype. I suspect once he's done and merged I may show converting it to pytest |
I open this ticket because we need to migrate the rest of the tests to complete the migrations. |
Hello,
Overview
Currently, Helm Chart for Airflow has two types of tests: (Learn the best practices of Helm Chart testing)
In each case, we use a different framework:
Start reading here
Today I would like to talk about template testing. In my opinion, using helm-unittest is not a very good solution.
During the discussion with @dimberman, I prepared a small POC that shows how we can test the Helm Chart with Pytest + Python.
Here is link: #11533 (comment)
Alternatively, we can also migrate to terratest, which has native Helm Chart integration but uses Go-lang.
Now there is a question for the community. What do you think about it? Should we migrate all tests to Pytestt? Is this the only reason contributors don't add unit tests? What else can we do to encourage contributors to write tests?
Best regards,
Kamil Breguła
The text was updated successfully, but these errors were encountered: