pytest-xdocker 0.2.8__tar.gz → 0.2.9__tar.gz

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.
Files changed (56) hide show
  1. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/CHANGES.rst +7 -0
  2. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/PKG-INFO +1 -1
  3. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/xdocker.py +36 -12
  4. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_xdocker.py +34 -1
  5. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.editorconfig +0 -0
  6. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.gitattributes +0 -0
  7. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.github/CODEOWNERS +0 -0
  8. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.github/actions/setup-uv-env/action.yml +0 -0
  9. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.github/workflows/publish.yml +0 -0
  10. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.github/workflows/test.yml +0 -0
  11. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.gitignore +0 -0
  12. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.venv.pth +0 -0
  13. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.vscode/extensions.json +0 -0
  14. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.vscode/launch.json +0 -0
  15. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/.vscode/settings.json +0 -0
  16. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/CONTRIBUTING.rst +0 -0
  17. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/LICENSE.rst +0 -0
  18. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/Makefile +0 -0
  19. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/README.rst +0 -0
  20. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/STYLE_GUIDE.rst +0 -0
  21. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/docs/changes.rst +0 -0
  22. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/docs/conf.py +0 -0
  23. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/docs/contributing.rst +0 -0
  24. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/docs/index.rst +0 -0
  25. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/docs/license.rst +0 -0
  26. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/docs/modules.rst +0 -0
  27. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/docs/pytest_xdocker.rst +0 -0
  28. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/docs/style_guide.rst +0 -0
  29. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/environment.yml +0 -0
  30. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/poetry.toml +0 -0
  31. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pyproject.toml +0 -0
  32. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/__init__.py +0 -0
  33. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/cache.py +0 -0
  34. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/command.py +0 -0
  35. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/docker.py +0 -0
  36. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/fixtures.py +0 -0
  37. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/lock.py +0 -0
  38. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/network.py +0 -0
  39. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/process.py +0 -0
  40. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/retry.py +0 -0
  41. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/pytest_xdocker/validators.py +0 -0
  42. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/setup.py +0 -0
  43. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/integration/__init__.py +0 -0
  44. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/integration/test_process.py +0 -0
  45. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/integration/test_xdocker.py +0 -0
  46. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/__init__.py +0 -0
  47. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_cache.py +0 -0
  48. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_command.py +0 -0
  49. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_docker.py +0 -0
  50. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_fixtures.py +0 -0
  51. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_lock.py +0 -0
  52. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_network.py +0 -0
  53. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_process.py +0 -0
  54. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_retry.py +0 -0
  55. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/tests/unit/test_validators.py +0 -0
  56. {pytest_xdocker-0.2.8 → pytest_xdocker-0.2.9}/uv.lock +0 -0
@@ -1,3 +1,10 @@
1
+ Version 0.2.9
2
+ -------------
3
+
4
+ Released 2025-05-20
5
+
6
+ - Add docker up.
7
+
1
8
  Version 0.2.8
2
9
  -------------
3
10
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-xdocker
3
- Version: 0.2.8
3
+ Version: 0.2.9
4
4
  Summary: Pytest fixture to run docker across test runs.
5
5
  Author-email: Marc Tardif <marc@interunion.ca>
6
6
  License-File: LICENSE.rst
@@ -48,21 +48,28 @@ def docker_call(*args, command=docker):
48
48
  args.pop(0)
49
49
  command = command.compose()
50
50
 
51
- if "run" not in args:
52
- raise ValueError(f"Only xdocker [compose] run is supported, got: {args}")
51
+ if "run" in args:
52
+ while args[0] != "run":
53
+ command = command.with_optionals(args.pop(0))
53
54
 
54
- while args[0] != "run":
55
- command = command.with_optionals(args.pop(0))
55
+ args.pop(0)
56
+ command = Command("run", command)
57
+
58
+ # Pull the latest image.
59
+ for arg in args:
60
+ if arg.endswith(":latest"):
61
+ docker.pull(arg).execute()
56
62
 
57
- args.pop(0)
58
- command = Command("run", command)
63
+ return docker_run(*args, command=command)
59
64
 
60
- # Pull the latest image.
61
- for arg in args:
62
- if arg.endswith(":latest"):
63
- docker.pull(arg).execute()
65
+ if "up" in args:
66
+ while args[0] != "up":
67
+ command = command.with_optionals(args.pop(0))
64
68
 
65
- return docker_run(*args, command=command)
69
+ args.pop(0)
70
+ return docker_up(*args, command=command)
71
+
72
+ raise ValueError(f"Only xdocker [compose] run/up is supported, got: {args}")
66
73
 
67
74
 
68
75
  def docker_run(*args, command=docker.command("run")): # noqa: B008
@@ -75,7 +82,7 @@ def docker_run(*args, command=docker.command("run")): # noqa: B008
75
82
  try:
76
83
  output = command.with_optionals("--detach").with_positionals(*args).execute(stderr=STDOUT)
77
84
  except CalledProcessError as error:
78
- match = re.search(r'The container name "/(?P<name>[^"]+)" is already in use', error.output)
85
+ match = re.search(r'The container name "/?(?P<name>[^"]+)" is already in use', error.output)
79
86
  if not match:
80
87
  raise
81
88
 
@@ -89,6 +96,23 @@ def docker_run(*args, command=docker.command("run")): # noqa: B008
89
96
  return match.group("name")
90
97
 
91
98
 
99
+ def docker_up(*args, command):
100
+ """Start a Docker Compose service detached and return the container name."""
101
+ options = [a for a in args if a.startswith("-")]
102
+ services = [a for a in args if not a.startswith("-")]
103
+
104
+ up_command = Command("up", command).with_optionals("-d", *options).with_positionals(*services)
105
+ up_command.execute(stderr=STDOUT)
106
+
107
+ # Get the container name from docker compose ps.
108
+ ps_command = Command("ps", command).with_optionals("--format", "{{.Name}}").with_positionals(*services)
109
+ output = ps_command.execute(stderr=STDOUT).strip()
110
+ if not output:
111
+ return None
112
+
113
+ return output.splitlines()[-1]
114
+
115
+
92
116
  def wait_ppid(ppid=None, interval=1):
93
117
  """
94
118
  Wait for a parent PID to exit (become a zombie).
@@ -14,6 +14,7 @@ from pytest_xdocker.xdocker import (
14
14
  docker_call,
15
15
  docker_remove,
16
16
  docker_run,
17
+ docker_up,
17
18
  main,
18
19
  monitor_container,
19
20
  )
@@ -26,7 +27,7 @@ def test_docker_remove_non_existing(unique):
26
27
 
27
28
 
28
29
  def test_docker_call(unique):
29
- """Calling a command other than run should raise."""
30
+ """Calling a command other than run or up should raise."""
30
31
  with pytest.raises(ValueError):
31
32
  docker_call("rm")
32
33
 
@@ -55,6 +56,38 @@ def test_docker_run_already_in_use(unique):
55
56
  assert result is None
56
57
 
57
58
 
59
+ def test_docker_run_already_in_use_no_slash(unique):
60
+ """Running a docker container already in use without leading slash should return None."""
61
+ name = unique("text")
62
+ command = Mock(
63
+ with_optionals=Mock(
64
+ side_effect=CalledProcessError(1, "", output=f'The container name "{name}" is already in use')
65
+ )
66
+ )
67
+ result = docker_run(command=command)
68
+ assert result is None
69
+
70
+
71
+ @patch("pytest_xdocker.xdocker.Command")
72
+ def test_docker_up(mock_command, unique):
73
+ """Starting a compose service with up should return its container name."""
74
+ name = unique("text")
75
+ up_instance = Mock()
76
+ up_instance.with_optionals.return_value = up_instance
77
+ up_instance.with_positionals.return_value = up_instance
78
+
79
+ ps_instance = Mock()
80
+ ps_instance.with_optionals.return_value = ps_instance
81
+ ps_instance.with_positionals.return_value = ps_instance
82
+ ps_instance.execute.return_value = f"{name}\n"
83
+
84
+ mock_command.side_effect = [up_instance, ps_instance]
85
+
86
+ command = Mock()
87
+ result = docker_up("--build", "mysql", command=command)
88
+ assert result == name
89
+
90
+
58
91
  @patch("pytest_xdocker.xdocker.DockerContainer")
59
92
  @patch("pytest_xdocker.xdocker.check_call")
60
93
  def test_monitor_container_normal_exit(cc_mock, dc_mock, unique):
File without changes
File without changes
File without changes
File without changes