pytest-qfield-e2e 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ # Copyright (C) 2026 qfield-dev-tools Contributors.
2
+ #
3
+ #
4
+ # This file is part of qfield-dev-tools.
5
+ #
6
+ # qfield-dev-tools is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # qfield-dev-tools is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with qfield-dev-tools. If not, see <https://www.gnu.org/licenses/>.
18
+
19
+ """Pytest fixtures that drive a real QField app."""
@@ -0,0 +1,279 @@
1
+ # Copyright (C) 2026 qfield-dev-tools Contributors.
2
+ #
3
+ #
4
+ # This file is part of qfield-dev-tools.
5
+ #
6
+ # qfield-dev-tools is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # qfield-dev-tools is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with qfield-dev-tools. If not, see <https://www.gnu.org/licenses/>.
18
+
19
+ """Pytest fixtures running a local QFieldCloud and devices synced with it."""
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import time
25
+ from contextlib import suppress
26
+ from pathlib import Path
27
+ from typing import TYPE_CHECKING, Any
28
+
29
+ import pytest
30
+
31
+ from qfield_driver import actions
32
+ from qfield_driver.cloud.stack import (
33
+ HOSTED,
34
+ SOURCE_ENV,
35
+ QFieldCloudStack,
36
+ local_ref,
37
+ resolve_ref,
38
+ )
39
+
40
+ if TYPE_CHECKING:
41
+ from collections.abc import Callable, Generator, Iterator
42
+
43
+ from qfield_driver.app import QFieldApp
44
+ from qfield_driver.cloud.client import QFieldCloudClient
45
+
46
+ REF_ENV = "QFIELDCLOUD_REF"
47
+ WORKER_ENV = "PYTEST_XDIST_WORKER"
48
+ USED_STACK = pytest.StashKey[dict[str, Any]]()
49
+ DEFAULT_PASSWORD = "pytest-qfield-123" # noqa: S105 disposable local test stack
50
+
51
+
52
+ def pytest_addoption(parser: pytest.Parser) -> None:
53
+ group = parser.getgroup("qfieldcloud")
54
+ group.addoption(
55
+ "--qfieldcloud-ref",
56
+ help=(
57
+ "QFieldCloud release: `hosted` (what app.qfield.cloud runs, default),"
58
+ f" `latest` or a tag. Env {REF_ENV}."
59
+ ),
60
+ )
61
+ group.addoption(
62
+ "--qfieldcloud-down",
63
+ action="store_true",
64
+ help="Remove the QFieldCloud stack and its data after the session.",
65
+ )
66
+ parser.addini("qfieldcloud_ref", "QFieldCloud release, see --qfieldcloud-ref.")
67
+ group.addoption(
68
+ "--qfieldcloud-source-dir",
69
+ help=f"QFieldCloud checkout of your own to run. Env {SOURCE_ENV}.",
70
+ )
71
+ parser.addini(
72
+ "qfieldcloud_source_dir", "QFieldCloud checkout, relative to the rootdir."
73
+ )
74
+ parser.addini("qfieldcloud_https_port", "Host HTTPS port, 8543 by default.")
75
+
76
+
77
+ def pytest_configure(config: pytest.Config) -> None:
78
+ config.addinivalue_line(
79
+ "markers", "qfieldcloud: test needs a local QFieldCloud stack, docker or podman"
80
+ )
81
+
82
+
83
+ def worker_username(username: str) -> str:
84
+ """Return a username of this pytest-xdist worker, so workers never share a user.
85
+
86
+ One cloud token is valid on one device, parallel tests would log each
87
+ other out. Outside xdist names stay as they are.
88
+ """
89
+ worker = os.environ.get(WORKER_ENV)
90
+ if not worker or username.endswith(f"_{worker}"):
91
+ return username
92
+ return f"{username}_{worker}"
93
+
94
+
95
+ def pytest_sessionfinish(session: pytest.Session) -> None:
96
+ """Remove the stack xdist workers used, once all of them are done."""
97
+ config = session.config
98
+ used = config.stash.get(USED_STACK, None)
99
+ if used and config.getoption("qfieldcloud_down") and not os.environ.get(WORKER_ENV):
100
+ QFieldCloudStack(
101
+ used["ref"],
102
+ Path(used["cache_dir"]),
103
+ name=used["name"],
104
+ source=Path(used["source"]) if used["source"] else None,
105
+ ).down()
106
+
107
+
108
+ @pytest.hookimpl(optionalhook=True)
109
+ def pytest_testnodedown(node: Any, error: object) -> None: # noqa: ANN401, ARG001
110
+ """Hear from xdist workers which stack they used."""
111
+ output = getattr(node, "workeroutput", {})
112
+ if "qfieldcloud_stack" in output:
113
+ node.config.stash[USED_STACK] = output["qfieldcloud_stack"]
114
+
115
+
116
+ @pytest.hookimpl(wrapper=True)
117
+ def pytest_fixture_setup(
118
+ fixturedef: pytest.FixtureDef[Any], request: pytest.FixtureRequest
119
+ ) -> Generator[None, Any, Any]:
120
+ """Tell the xdist controller which stack a worker used, overrides included."""
121
+ result = yield
122
+ output = getattr(request.config, "workeroutput", None)
123
+ if fixturedef.argname == "qfieldcloud_stack" and output is not None:
124
+ output["qfieldcloud_stack"] = {
125
+ "ref": result.ref,
126
+ "cache_dir": str(result.cache_dir),
127
+ "name": result.name,
128
+ "source": str(result.source) if result.source else None,
129
+ }
130
+ return result
131
+
132
+
133
+ def local_source(config: pytest.Config) -> Path | None:
134
+ """Return the configured QFieldCloud checkout of your own, if any."""
135
+ if configured := config.getoption("qfieldcloud_source_dir") or os.environ.get(
136
+ SOURCE_ENV
137
+ ):
138
+ return Path(configured)
139
+ if configured := config.getini("qfieldcloud_source_dir"):
140
+ return config.rootpath / configured
141
+ return None
142
+
143
+
144
+ @pytest.fixture(scope="session")
145
+ def qfieldcloud_ref(pytestconfig: pytest.Config) -> str:
146
+ """Return the QFieldCloud tag under test, resolved from `hosted` or `latest`.
147
+
148
+ With a checkout of your own, `local-<directory>`.
149
+ """
150
+ if source := local_source(pytestconfig):
151
+ return local_ref(source.expanduser().resolve())
152
+ ref = (
153
+ pytestconfig.getoption("qfieldcloud_ref")
154
+ or os.environ.get(REF_ENV)
155
+ or pytestconfig.getini("qfieldcloud_ref")
156
+ or HOSTED
157
+ )
158
+ return resolve_ref(str(ref))
159
+
160
+
161
+ @pytest.fixture(scope="session")
162
+ def qfieldcloud_stack(
163
+ pytestconfig: pytest.Config, qfieldcloud_ref: str, qfield_fetch_cache_dir: Path
164
+ ) -> Iterator[QFieldCloudStack]:
165
+ """Start a local QFieldCloud, reused across sessions until removed.
166
+
167
+ Workers of pytest-xdist share it. Override to change ports or pass extra
168
+ `.env` values.
169
+ """
170
+ if source := local_source(pytestconfig):
171
+ stack = QFieldCloudStack.local(source, qfield_fetch_cache_dir)
172
+ else:
173
+ stack = QFieldCloudStack(qfieldcloud_ref, qfield_fetch_cache_dir)
174
+ if port := pytestconfig.getini("qfieldcloud_https_port"):
175
+ stack.https_port = int(port)
176
+ stack.up()
177
+ yield stack
178
+ # Under xdist the controller removes it once every worker is done.
179
+ if pytestconfig.getoption("qfieldcloud_down") and not os.environ.get(WORKER_ENV):
180
+ stack.down()
181
+
182
+
183
+ @pytest.fixture(scope="session")
184
+ def qfieldcloud_admin(qfieldcloud_stack: QFieldCloudStack) -> QFieldCloudClient:
185
+ from qfield_driver.cloud.client import QFieldCloudClient # noqa: PLC0415
186
+
187
+ username, password = qfieldcloud_stack.admin
188
+ if worker_username(username) != username:
189
+ # A login ends the user's other sessions, so each worker has its own.
190
+ username = worker_username(username)
191
+ qfieldcloud_stack.ensure_user(username, password, superuser=True)
192
+ return QFieldCloudClient(
193
+ qfieldcloud_stack.url,
194
+ username,
195
+ password,
196
+ verify=qfieldcloud_stack.ca_certificate,
197
+ )
198
+
199
+
200
+ @pytest.fixture(scope="session")
201
+ def qfieldcloud_user(
202
+ qfieldcloud_stack: QFieldCloudStack,
203
+ ) -> Callable[..., QFieldCloudClient]:
204
+ """Create a plain user once per session, and return a client logged in as it.
205
+
206
+ One cloud token is valid on one device at a time, so give each device a user.
207
+ """
208
+ from qfield_driver.cloud.client import QFieldCloudClient # noqa: PLC0415
209
+
210
+ def user(username: str, password: str = DEFAULT_PASSWORD) -> QFieldCloudClient:
211
+ username = worker_username(username)
212
+ qfieldcloud_stack.ensure_user(username, password)
213
+ return QFieldCloudClient(
214
+ qfieldcloud_stack.url,
215
+ username,
216
+ password,
217
+ verify=qfieldcloud_stack.ca_certificate,
218
+ )
219
+
220
+ return user
221
+
222
+
223
+ @pytest.fixture
224
+ def qfieldcloud_project(
225
+ qfieldcloud_admin: QFieldCloudClient,
226
+ ) -> Iterator[Callable[..., str]]:
227
+ """Upload a project directory as a new cloud project and return its id.
228
+
229
+ The project is packaged, and deleted after the test.
230
+
231
+ :param collaborators: Usernames added as editors
232
+ """
233
+ created: list[str] = []
234
+
235
+ def create(
236
+ directory: Path, name: str | None = None, collaborators: tuple[str, ...] = ()
237
+ ) -> str:
238
+ project_id = qfieldcloud_admin.create_project(
239
+ name or f"pytest_{time.time_ns()}"
240
+ )
241
+ created.append(project_id)
242
+ for username in collaborators:
243
+ qfieldcloud_admin.add_collaborator(project_id, worker_username(username))
244
+ qfieldcloud_admin.upload(project_id, directory)
245
+ qfieldcloud_admin.package(project_id)
246
+ return project_id
247
+
248
+ yield create
249
+ for project_id in created:
250
+ with suppress(Exception):
251
+ qfieldcloud_admin.delete_project(project_id)
252
+
253
+
254
+ @pytest.fixture
255
+ def qfieldcloud_device(
256
+ qfield_app_factory: Callable[..., QFieldApp],
257
+ qfieldcloud_stack: QFieldCloudStack,
258
+ ) -> Callable[..., QFieldApp]:
259
+ """Start a QField, log it in, and download and open a cloud project.
260
+
261
+ :param grant_plugin: The project ships a project plugin to allow
262
+ """
263
+
264
+ def start(
265
+ project_id: str,
266
+ username: str,
267
+ password: str = DEFAULT_PASSWORD,
268
+ *,
269
+ name: str | None = None,
270
+ grant_plugin: bool = False,
271
+ ) -> QFieldApp:
272
+ username = worker_username(username)
273
+ app = qfield_app_factory(name or username)
274
+ actions.login(app, qfieldcloud_stack.url, username, password)
275
+ project_file = actions.download_project(app, project_id)
276
+ actions.open_project(app, project_file, grant_plugin=grant_plugin)
277
+ return app
278
+
279
+ return start
@@ -0,0 +1,240 @@
1
+ # Copyright (C) 2026 qfield-dev-tools Contributors.
2
+ #
3
+ #
4
+ # This file is part of qfield-dev-tools.
5
+ #
6
+ # qfield-dev-tools is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # qfield-dev-tools is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with qfield-dev-tools. If not, see <https://www.gnu.org/licenses/>.
18
+
19
+ """Pytest fixtures starting real QField apps."""
20
+
21
+ from __future__ import annotations
22
+
23
+ import itertools
24
+ import json
25
+ import logging
26
+ import os
27
+ from contextlib import ExitStack
28
+ from pathlib import Path
29
+ from typing import TYPE_CHECKING
30
+
31
+ import pytest
32
+
33
+ from qfield_driver.app import BINARY_ENV, DriverError, QFieldApp, local_app
34
+ from qfield_fetch import appimage, release_version
35
+ from qfield_fetch.pytest_plugin import configured_version
36
+
37
+ if TYPE_CHECKING:
38
+ from collections.abc import Callable, Generator, Iterator
39
+
40
+ LOGGER = logging.getLogger(__name__)
41
+ APPS_KEY = pytest.StashKey[list[tuple[str, QFieldApp, Path]]]()
42
+ DEFAULT_VERSION = "4.2.9"
43
+
44
+
45
+ def pytest_addoption(parser: pytest.Parser) -> None:
46
+ group = parser.getgroup("qfield-app")
47
+ group.addoption(
48
+ "--qfield-app-binary",
49
+ help=(
50
+ "QField of your own to run instead of a fetched release: an AppRun,"
51
+ f" an AppImage or a build. Env {BINARY_ENV}."
52
+ ),
53
+ )
54
+ parser.addini(
55
+ "qfield_app_binary", "QField to run, relative to the rootdir, see above."
56
+ )
57
+ group.addoption(
58
+ "--qfield-app-reuse",
59
+ action="store_true",
60
+ help=(
61
+ "Keep each device running between tests and reset it instead of"
62
+ " restarting. Faster, but settings a test changes stay."
63
+ ),
64
+ )
65
+ parser.addini(
66
+ "qfield_app_reuse",
67
+ "Reuse running devices, see --qfield-app-reuse.",
68
+ type="bool",
69
+ default=False,
70
+ )
71
+
72
+
73
+ def pytest_configure(config: pytest.Config) -> None:
74
+ config.addinivalue_line(
75
+ "markers", "qfield_app: test runs a real QField app, Linux and Xvfb only"
76
+ )
77
+
78
+
79
+ @pytest.hookimpl(wrapper=True)
80
+ def pytest_runtest_makereport(
81
+ item: pytest.Item, call: pytest.CallInfo[None]
82
+ ) -> Generator[None, pytest.TestReport, pytest.TestReport]:
83
+ """Add each device's screenshot, message log and log tail to a failure."""
84
+ report = yield
85
+ if report.failed and call.when in ("setup", "call"):
86
+ for name, app, directory in item.stash.get(APPS_KEY, []):
87
+ report.sections.append(
88
+ (f"QField {name}", app.diagnose(directory, f"{call.when}-{name}"))
89
+ )
90
+ return report
91
+
92
+
93
+ @pytest.fixture(scope="session")
94
+ def qfield_app_version(pytestconfig: pytest.Config) -> str:
95
+ """Return the QField release under test, `latest` resolved."""
96
+ return release_version(configured_version(pytestconfig) or DEFAULT_VERSION)
97
+
98
+
99
+ @pytest.fixture(scope="session")
100
+ def qfield_app_binary(
101
+ request: pytest.FixtureRequest,
102
+ pytestconfig: pytest.Config,
103
+ qfield_fetch_cache_dir: Path,
104
+ ) -> Path:
105
+ """Return the configured QField, or the `AppRun` of the fetched release."""
106
+ if configured := pytestconfig.getoption("qfield_app_binary") or os.environ.get(
107
+ BINARY_ENV
108
+ ):
109
+ return local_app(configured)
110
+ if configured := pytestconfig.getini("qfield_app_binary"):
111
+ return local_app(pytestconfig.rootpath / configured)
112
+ version = request.getfixturevalue("qfield_app_version")
113
+ return appimage(version, qfield_fetch_cache_dir)
114
+
115
+
116
+ @pytest.fixture
117
+ def qfield_app_plugins() -> dict[str, Path]:
118
+ """App plugins to install in every started QField, by uuid.
119
+
120
+ Override to install the plugin under test as a real app plugin.
121
+ """
122
+ return {}
123
+
124
+
125
+ @pytest.fixture
126
+ def qfield_app_settings() -> dict[str, object]:
127
+ """QField settings written to every profile before QField starts.
128
+
129
+ Keys are QSettings keys, `myplugin/interval` for example. Override to set them.
130
+ """
131
+ return {}
132
+
133
+
134
+ class _Pool:
135
+ """Running devices kept between tests, one per name."""
136
+
137
+ def __init__(self, directory: Path) -> None:
138
+ self.directory = directory
139
+ self.apps: dict[str, tuple[str, QFieldApp]] = {}
140
+ self._homes = itertools.count()
141
+
142
+ def get(self, name: str, key: str, start: Callable[[Path], QFieldApp]) -> QFieldApp:
143
+ if name in self.apps:
144
+ old_key, app = self.apps.pop(name)
145
+ if old_key == key and app.running:
146
+ try:
147
+ app.reset()
148
+ except (DriverError, TimeoutError):
149
+ LOGGER.warning("Could not reset %s, starting it again", name)
150
+ else:
151
+ self.apps[name] = (key, app)
152
+ return app
153
+ app.close()
154
+ app = start(self.directory / f"{name}-{next(self._homes)}")
155
+ self.apps[name] = (key, app)
156
+ return app
157
+
158
+ def close(self) -> None:
159
+ for _key, app in self.apps.values():
160
+ app.close()
161
+ self.apps.clear()
162
+
163
+
164
+ @pytest.fixture(scope="session")
165
+ def _qfield_app_pool(
166
+ pytestconfig: pytest.Config, tmp_path_factory: pytest.TempPathFactory
167
+ ) -> Iterator[_Pool | None]:
168
+ reuse = pytestconfig.getoption("qfield_app_reuse") or pytestconfig.getini(
169
+ "qfield_app_reuse"
170
+ )
171
+ if not reuse:
172
+ yield None
173
+ return
174
+ pool = _Pool(tmp_path_factory.mktemp("qfield-devices"))
175
+ yield pool
176
+ pool.close()
177
+
178
+
179
+ @pytest.fixture
180
+ def qfield_app_factory(
181
+ request: pytest.FixtureRequest,
182
+ tmp_path: Path,
183
+ qfield_app_binary: Path,
184
+ qfield_app_plugins: dict[str, Path],
185
+ qfield_app_settings: dict[str, object],
186
+ _qfield_app_pool: _Pool | None,
187
+ ) -> Iterator[Callable[..., QFieldApp]]:
188
+ """Start QField apps, each with its own profile and display.
189
+
190
+ Call it with a device name, one profile directory per name. With
191
+ `--qfield-app-reuse` a device started with the same plugins and settings
192
+ in an earlier test is reset and handed out again.
193
+ """
194
+ started = request.node.stash.setdefault(APPS_KEY, [])
195
+ with ExitStack() as stack:
196
+
197
+ def start(
198
+ name: str = "device",
199
+ app_plugins: dict[str, Path] | None = None,
200
+ ) -> QFieldApp:
201
+ # Two running apps on one profile overwrite each other's files.
202
+ if any(name == other and app.running for other, app, _dir in started):
203
+ msg = f"Device {name!r} is already running in this test"
204
+ raise ValueError(msg)
205
+ plugins = qfield_app_plugins if app_plugins is None else app_plugins
206
+
207
+ def new(home: Path) -> QFieldApp:
208
+ app = QFieldApp(
209
+ qfield_app_binary,
210
+ home,
211
+ app_plugins=plugins,
212
+ settings=qfield_app_settings,
213
+ # Fixtures run on the main thread, which pytest keeps.
214
+ die_with_parent=True,
215
+ )
216
+ return app.__enter__()
217
+
218
+ if _qfield_app_pool is None:
219
+ app = new(tmp_path / name)
220
+ stack.callback(app.close)
221
+ else:
222
+ key = json.dumps(
223
+ [
224
+ sorted((name, str(path)) for name, path in plugins.items()),
225
+ qfield_app_settings,
226
+ ],
227
+ sort_keys=True,
228
+ default=str,
229
+ )
230
+ app = _qfield_app_pool.get(name, key, new)
231
+ started.append((name, app, tmp_path))
232
+ return app
233
+
234
+ yield start
235
+
236
+
237
+ @pytest.fixture
238
+ def qfield_app(qfield_app_factory: Callable[..., QFieldApp]) -> QFieldApp:
239
+ """Start a QField with an isolated profile."""
240
+ return qfield_app_factory()
File without changes
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytest-qfield-e2e
3
+ Version: 0.1.0
4
+ Summary: Pytest fixtures for plugin and end-to-end tests on a real QField app
5
+ Keywords: pytest,QField,QFieldCloud,GIS,e2e
6
+ License-Expression: GPL-2.0-or-later
7
+ License-File: LICENSE
8
+ Classifier: Framework :: Pytest
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Software Development :: Testing
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Requires-Dist: pytest>=8
15
+ Requires-Dist: qfield-driver>=0.1.0,<0.2
16
+ Requires-Dist: qfield-fetch
17
+ Requires-Dist: qfield-driver[cloud]>=0.1.0,<0.2 ; extra == 'cloud'
18
+ Requires-Python: >=3.12
19
+ Project-URL: homepage, https://github.com/Joonalai/qfield-dev-tools
20
+ Project-URL: repository, https://github.com/Joonalai/qfield-dev-tools
21
+ Provides-Extra: cloud
22
+ Description-Content-Type: text/markdown
23
+
24
+ # pytest-qfield-e2e
25
+
26
+ Run plugin and end-to-end tests against a real QField app. Where `pytest-qfield`
27
+ renders plugin QML on QGIS with stubs, this plugin starts the stock QField release
28
+ AppImage through [qfield-driver](https://github.com/Joonalai/qfield-dev-tools/tree/main/components/qfield-driver)
29
+ and drives it like a user: real taps, real typing, real forms, real projects. The
30
+ `cloud` extra adds a local QFieldCloud for end-to-end tests with several devices
31
+ syncing through it.
32
+
33
+ Status: experimental. Linux x64 only. The system requirements are those of
34
+ [qfield-driver](https://github.com/Joonalai/qfield-dev-tools/tree/main/components/qfield-driver#requirements).
35
+
36
+ ## Fixtures
37
+
38
+ | Fixture | Scope | What |
39
+ | --- | --- | --- |
40
+ | `qfield_app_version` | session | Release under test, from `--qfield-version`, env `QFIELD_VERSION`, ini `qfield_version`, default `4.2.9`. `latest` resolves the newest release. |
41
+ | `qfield_app_binary` | session | QField of your own from `--qfield-app-binary`, env `QFIELD_APP_BINARY` or ini `qfield_app_binary`: an AppRun, an AppImage (runs through FUSE) or a build. Otherwise the extracted `AppRun`, fetched once by [qfield-fetch](https://github.com/Joonalai/qfield-dev-tools/tree/main/components/qfield-fetch) into `~/.cache/qfield-fetch` (env `QFIELD_FETCH_CACHE_DIR`, ini `qfield_fetch_cache_dir`). |
42
+ | `qfield_app_plugins` | function | App plugins installed in every started app, `{uuid: directory}`. Empty by default. |
43
+ | `qfield_app_settings` | function | QField settings written before start, `{"myplugin/interval": 50}`. For values a plugin reads once on load. |
44
+ | `qfield_app_factory` | function | `start(name="device", app_plugins=None)` starts another app with its own profile. |
45
+ | `qfield_app` | function | One running app, a `qfield_driver.app.QFieldApp`. |
46
+
47
+ With the `cloud` extra (`pytest-qfield-e2e[cloud]`):
48
+
49
+ | Fixture | Scope | What |
50
+ | --- | --- | --- |
51
+ | `qfieldcloud_ref` | session | QFieldCloud release: `hosted` (default), `latest` or a tag. `--qfieldcloud-ref`, env `QFIELDCLOUD_REF`, ini `qfieldcloud_ref`. With a checkout of your own (`--qfieldcloud-source-dir`, env `QFIELDCLOUD_SOURCE_DIR`, ini `qfieldcloud_source_dir`) it is `local-<directory>`, and the stack writes its `.env` and compose overrides into that checkout. |
52
+ | `qfieldcloud_stack` | session | The official compose stack at that release, built and started once, then reused across sessions. `--qfieldcloud-down` removes it after the session. Ini `qfieldcloud_https_port` changes its HTTPS port. |
53
+ | `qfieldcloud_admin` | session | REST client logged in as the admin. |
54
+ | `qfieldcloud_user` | session | `user(name, password=...)` creates a user once and returns its client. |
55
+ | `qfieldcloud_project` | function | `create(directory, name=None, collaborators=())` uploads and packages a project, deleted after the test. |
56
+ | `qfieldcloud_device` | function | `start(project_id, username, ...)` starts QField, logs in, downloads and opens the project. |
57
+
58
+ ## Writing tests
59
+
60
+ ```python
61
+ from qfield_driver import actions
62
+
63
+
64
+ def test_button_logs(qfield_app, tmp_path):
65
+ qfield_app.host_plugin(PLUGIN_DIR / "main.qml")
66
+ actions.open_project(qfield_app, PROJECT_FILE)
67
+
68
+ actions.tap_object(qfield_app, "pluginButton")
69
+
70
+ actions.wait_for_message(qfield_app, "Plugin button clicked!")
71
+ assert qfield_app.eval("return plugin.clicks") == 1
72
+ ```
73
+
74
+ `qfield_app.eval`, `host_plugin`, the `actions` helpers and positioning are
75
+ documented in [qfield-driver](https://github.com/Joonalai/qfield-dev-tools/tree/main/components/qfield-driver#usage).
76
+ `qfield_app_plugins` installs the plugin under test as a real app plugin instead,
77
+ a black box.
78
+
79
+ ## QFieldCloud recipe
80
+
81
+ ```python
82
+ def test_edit_reaches_cloud(
83
+ project_dir,
84
+ qfieldcloud_user,
85
+ qfieldcloud_project,
86
+ qfieldcloud_device,
87
+ qfieldcloud_admin,
88
+ ):
89
+ qfieldcloud_user("surveyor")
90
+ project_id = qfieldcloud_project(project_dir, collaborators=("surveyor",))
91
+ app = qfieldcloud_device(project_id, "surveyor")
92
+
93
+ actions.edit_in_form(app, "points", "fid = 1", "text_field", "new")
94
+ pushed = actions.push(app, project_id)
95
+
96
+ deltas = qfieldcloud_admin.wait_for_deltas(project_id, pushed)
97
+ assert {d["status"] for d in deltas} == {"STATUS_APPLIED"}
98
+ ```
99
+
100
+ How the stack runs, and `qfield-driver-cloud` to start or remove it ahead of
101
+ a run, are in [qfield-driver](https://github.com/Joonalai/qfield-dev-tools/tree/main/components/qfield-driver#qfieldcloud).
102
+
103
+ ## Running
104
+
105
+ ```bash
106
+ pytest -p no:pytest-qfield -p no:pytest_qgis -p no:pytest-qt test_app
107
+ ```
108
+
109
+ The QGIS based plugins are not needed for app tests and importing Qt in the test
110
+ process is pointless, so disable them for app test runs.
111
+
112
+ Each test starts its own QField, about 5 s on a laptop. Device logs are in
113
+ `tmp_path/<device>.log`, and `qfield_app.screenshot(path)` saves the window.
114
+
115
+ A failing test gets a section per device in its report: the newest message log
116
+ lines, the log tail and a screenshot path. No screenshot is taken while a camera
117
+ view is open.
118
+
119
+ ### Faster runs
120
+
121
+ - `--qfield-app-reuse` (ini `qfield_app_reuse = true`) keeps each device running
122
+ and resets it between tests: plugin unhosted, popups closed, project cleared,
123
+ position lost, `state` emptied. A device is started again when the plugins or
124
+ settings differ. Settings a test changes stay, so keep it off for tests that
125
+ rely on a fresh profile. Reused devices log to the session's `qfield-devices`
126
+ temporary directory instead of `tmp_path`.
127
+ - `pytest-xdist` works, every device has its own display and ports. Workers
128
+ share one QFieldCloud stack and get their own users, `alice` becomes
129
+ `alice_gw1` through `worker_username`, which the cloud fixtures apply.
130
+ `--qfieldcloud-down` removes the stack once all workers are done.
@@ -0,0 +1,9 @@
1
+ pytest_qfield_e2e/__init__.py,sha256=07bRuQ5m972X6663tHQTZrEekEhTCpuDrpWG3gP2pVM,799
2
+ pytest_qfield_e2e/cloud.py,sha256=zALqvCuDI7W02ON2bFsWsP7BuHc2MYizoNypucgAOYw,9566
3
+ pytest_qfield_e2e/plugin.py,sha256=QZShbQrEceAbqA8reErBqEoopGzCL5KkeZp9rc2NGyY,8052
4
+ pytest_qfield_e2e/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ pytest_qfield_e2e-0.1.0.dist-info/licenses/LICENSE,sha256=8k_iW5ZzHftNC8WyT1MEd0UJVvm0WJnmQaWc8Ds3ODs,18073
6
+ pytest_qfield_e2e-0.1.0.dist-info/WHEEL,sha256=3OmCxFA0ffBIsX4x0o8CdfSvZAOvO3mzEG8U_z5TvV4,80
7
+ pytest_qfield_e2e-0.1.0.dist-info/entry_points.txt,sha256=onakU-99AcHj8233iaBA-fo2uGvtFQckbo0_St5WaTo,107
8
+ pytest_qfield_e2e-0.1.0.dist-info/METADATA,sha256=vy7GgFrIQdW5F6R_Fuv5tOMhfa_wYQF8KIj7LPczm_s,6667
9
+ pytest_qfield_e2e-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.13.8
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,4 @@
1
+ [pytest11]
2
+ pytest-qfield-e2e = pytest_qfield_e2e.plugin
3
+ pytest-qfield-e2e-cloud = pytest_qfield_e2e.cloud
4
+
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.