Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit d262a68

Browse files
committed
Fix tests for Python 3.13 and 3.14
1 parent e5df830 commit d262a68

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

tests/test_logging.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
from _pytask.database_utils import db
1717

1818

19+
def _clear_database() -> None:
20+
"""Delete records without using generator decompilation in Pony ORM."""
21+
for entity in db.entities.values():
22+
for record in entity.select():
23+
record.delete()
24+
25+
26+
_FAKE_CPYTHON_VERSION = "2.7.18 (main, Jul 31 2020, 01:53:57) [Clang 14.0.0]"
27+
28+
1929
@pytest.mark.end_to_end
2030
def test_existence_of_python_executable_in_db(tmp_path, runner):
2131
"""Test that the Python executable is stored in the database."""
@@ -34,8 +44,7 @@ def test_existence_of_python_executable_in_db(tmp_path, runner):
3444
assert python.path == sys.executable
3545

3646
orm.rollback()
37-
for entity in db.entities.values():
38-
orm.delete(e for e in entity)
47+
_clear_database()
3948

4049

4150
@pytest.mark.end_to_end
@@ -51,10 +60,6 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
5160
"""
5261
real_python_version = sys.version
5362
real_python_executable = sys.executable
54-
fake_version = (
55-
"2.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:57) "
56-
"[MSC v.1916 64 bit (AMD64)]"
57-
)
5863

5964
tmp_path.joinpath("pyproject.toml").write_text("[tool.pytask.ini_options]")
6065
source = "def task_dummy(): pass"
@@ -67,7 +72,7 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
6772
assert "Updating the information" in result.output
6873

6974
# Run with a fake version and not updating the environment.
70-
monkeypatch.setattr("pytask_environment.logging.sys.version", fake_version)
75+
monkeypatch.setattr("pytask_environment.logging.sys.version", _FAKE_CPYTHON_VERSION)
7176

7277
result = runner.invoke(cli)
7378
assert result.exit_code == ExitCode.FAILED
@@ -79,7 +84,7 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
7984
assert python.path == real_python_executable
8085

8186
# Run with a fake version and updating the environment.
82-
monkeypatch.setattr("pytask_environment.logging.sys.version", fake_version)
87+
monkeypatch.setattr("pytask_environment.logging.sys.version", _FAKE_CPYTHON_VERSION)
8388
monkeypatch.setattr("pytask_environment.logging.sys.executable", "new_path")
8489

8590
result = runner.invoke(cli, ["--update-environment", tmp_path.as_posix()])
@@ -88,12 +93,11 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
8893
with orm.db_session:
8994
python = Environment["python"]
9095

91-
assert python.version == fake_version
96+
assert python.version == _FAKE_CPYTHON_VERSION
9297
assert python.path == "new_path"
9398

9499
orm.rollback()
95-
for entity in db.entities.values():
96-
orm.delete(e for e in entity)
100+
_clear_database()
97101

98102

99103
@pytest.mark.end_to_end
@@ -103,10 +107,6 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
103107
def test_python_version_changed(
104108
monkeypatch, tmp_path, runner, check_python_version, expected
105109
):
106-
fake_version = (
107-
"2.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:57) "
108-
"[MSC v.1916 64 bit (AMD64)]"
109-
)
110110
tmp_path.joinpath("pyproject.toml").write_text(
111111
f"[tool.pytask.ini_options]\ncheck_python_version = {check_python_version}"
112112
)
@@ -120,15 +120,14 @@ def test_python_version_changed(
120120
assert "Updating the information" in result.output
121121

122122
# Run with a fake version and not updating the environment.
123-
monkeypatch.setattr("pytask_environment.logging.sys.version", fake_version)
123+
monkeypatch.setattr("pytask_environment.logging.sys.version", _FAKE_CPYTHON_VERSION)
124124

125125
result = runner.invoke(cli, [tmp_path.as_posix()])
126126
assert result.exit_code == expected
127127

128128
with orm.db_session:
129129
orm.rollback()
130-
for entity in db.entities.values():
131-
orm.delete(e for e in entity)
130+
_clear_database()
132131

133132

134133
@pytest.mark.end_to_end
@@ -158,5 +157,4 @@ def test_environment_changed(
158157

159158
with orm.db_session:
160159
orm.rollback()
161-
for entity in db.entities.values():
162-
orm.delete(e for e in entity)
160+
_clear_database()

0 commit comments

Comments
 (0)