From 4f5e5c9bb68515ddc07c78c4b256011fc76c8a5f Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:31:51 +1300 Subject: [PATCH] test(python_runner): add integration tests (#11638) * test(python_runner): add integration tests * simplify the test * add missing quotes * use setup_remote_tmp_dir * build venv manually first --- .../integration/targets/python_runner/aliases | 5 +++ .../targets/python_runner/meta/main.yml | 7 +++ .../targets/python_runner/tasks/main.yml | 43 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 tests/integration/targets/python_runner/aliases create mode 100644 tests/integration/targets/python_runner/meta/main.yml create mode 100644 tests/integration/targets/python_runner/tasks/main.yml diff --git a/tests/integration/targets/python_runner/aliases b/tests/integration/targets/python_runner/aliases new file mode 100644 index 0000000000..2df23d823c --- /dev/null +++ b/tests/integration/targets/python_runner/aliases @@ -0,0 +1,5 @@ +# Copyright (c) 2026, Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +azp/posix/2 diff --git a/tests/integration/targets/python_runner/meta/main.yml b/tests/integration/targets/python_runner/meta/main.yml new file mode 100644 index 0000000000..64e2009642 --- /dev/null +++ b/tests/integration/targets/python_runner/meta/main.yml @@ -0,0 +1,7 @@ +--- +# Copyright (c) 2026, Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +dependencies: + - setup_remote_tmp_dir diff --git a/tests/integration/targets/python_runner/tasks/main.yml b/tests/integration/targets/python_runner/tasks/main.yml new file mode 100644 index 0000000000..10d3ca7f0e --- /dev/null +++ b/tests/integration/targets/python_runner/tasks/main.yml @@ -0,0 +1,43 @@ +# Copyright (c) 2026, Alexei Znamensky +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: Create virtualenv + ansible.builtin.command: + cmd: "{{ ansible_python_interpreter }} -m venv {{ remote_tmp_dir }}/venv" + +- name: Update pip in virtualenv + ansible.builtin.pip: + name: pip + state: latest + virtualenv: "{{ remote_tmp_dir }}/venv" + +- name: Install django in virtualenv + ansible.builtin.pip: + name: django + state: present + virtualenv: "{{ remote_tmp_dir }}/venv" + +# Regression test for https://github.com/ansible-collections/community.general/issues/8884 +# Bug: PythonRunner was setting path_prefix to a string instead of a list, corrupting PATH +# when venv was specified, so the venv's python could not be found. +# The original reporter was running `migrate`; we use `check` to avoid needing a database. +- name: Create Django project using venv django-admin + ansible.builtin.command: + cmd: "{{ remote_tmp_dir }}/venv/bin/django-admin startproject testproject" + chdir: "{{ remote_tmp_dir }}" + +- name: Run django_command check on the created project (issue 8884 scenario) + community.general.django_command: + command: check + settings: testproject.settings + pythonpath: "{{ remote_tmp_dir }}/testproject" + venv: "{{ remote_tmp_dir }}/venv" + register: result_project_check + +- name: Assert project check succeeded and returned a version + ansible.builtin.assert: + that: + - result_project_check is success + - result_project_check.version is defined + - result_project_check.version != ""