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

Create a new pytest folder for live system testing with normal services #15688

Merged
merged 11 commits into from
Dec 6, 2024

Conversation

AlanCoding
Copy link
Member

@AlanCoding AlanCoding commented Dec 5, 2024

SUMMARY

This is intended to solve the problem of testing job-related behaviors.

The idea is to keep using as much of our normal testing system as possible, but not use the test database system. This is difficult with pytest-django installed. I can do it by creating a new test folder, and doing a cd into that. I've thought about it, and I'm willing to pay that price.

So I want to uninstall pytest-django, but without actually uninstalling it. I just take all its critical connection points and throw them in the trash. This means that the tests will operate directly on the database, unprotected. Just the way I like it. It is very easy to break things in this state, and that is just what we will do.

Unlike make test, this new make live_test can only be ran as a part of make docker-compose. That rule seems easy enough to me. It's honestly weird that make test runs in a single awx_devel container. If you were going to do that, don't bother with a container in the first place?

My demo test bypasses uWSGI, because didn't need it. It borrows the mock request fixtures we already have to make a "request". Why? Because it works. The task manager gets the message, dispatches it, and it does the full job lifecycle, events and all.

2024-12-05 04:29:41,706 INFO     [167a56f5] awx.main.commands.run_callback_receiver Starting EOF event processing for Job 23
2024-12-05 04:29:41,707 INFO     [167a56f5] awx.analytics.job_lifecycle job-23 post run {"type": "job", "task_id": 23, "state": "post_run", "work_unit_id": "awx1R9oUSnWU", "task_name": "Demo Job Template"}
2024-12-05 04:29:41,756 INFO     [167a56f5] awx.analytics.job_lifecycle job-23 finalize run {"type": "job", "task_id": 23, "state": "finalize_run", "work_unit_id": "awx1R9oUSnWU", "task_name": "Demo Job Template"}
2024-12-05 04:29:42,556 INFO     [-] awx.analytics.job_lifecycle job-23 stats wrapup finished {"type": "job", "task_id": 23, "state": "stats_wrapup_finished", "work_unit_id": "awx1R9oUSnWU", "task_name": "Demo Job Template"}

We want a philosophy of a test environment as isolated as reasonable, while still being useful. Because of that, it is never envisioned that we would make true API requests with this. It has the ORM, and everything can be done with that. The core goal of these tests are to see custody of jobs passed to the dispatcher/receptor/runner stack and test for outcomes in both the database and filesystem.

ISSUE TYPE
  • Breaking Change

@AlanCoding
Copy link
Member Author

Progress

>       assert job.status == 'successful', f'Job was not successful id={job.id} status={job.status}'
E       AssertionError: Job was not successful id=1 status=running
E       assert 'running' == 'successful'
E         
E         - successful
E         + running

this is almost certainly because it is still pulling the image, and increasing the timeout should do it.

@AlanCoding AlanCoding marked this pull request as ready for review December 5, 2024 16:34
@PabloHiro PabloHiro self-requested a review December 5, 2024 17:00
Copy link
Contributor

@PabloHiro PabloHiro left a comment

Choose a reason for hiding this comment

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

Awesome addition. Loving the README.md

Copy link

sonarqubecloud bot commented Dec 5, 2024

@@ -0,0 +1,3 @@
# This file is needed to undo the pytest settings from the project root
[pytest]
addopts = -p no:django -p awx.main.tests.live.pytest_django_config
Copy link
Member

Choose a reason for hiding this comment

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

what unsets DJANGO_SETTINGS_MODULE from awx/pytest.ini? is that what "no:django" does?

Copy link
Member Author

Choose a reason for hiding this comment

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

IIRC, it only respects the pytest.ini from the current directory, and you can only run these from the awx/main/tests/live directory. So the pytest.ini from a parent folder won't even be considered.

Using -p no:django disables the plugin "django", which has pytest_ prefixed, so the full plugin name is pytest_django. So this disables the pytest-django, it is installed as a library but pytest doesn't load it as a plugin.

Copy link
Member

Choose a reason for hiding this comment

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

ah okay thanks for the explanation

@AlanCoding AlanCoding merged commit 1a35775 into ansible:devel Dec 6, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants