Skip to content

Commit

Permalink
Merge pull request #166 from 15r10nk/fix_test_dependencies
Browse files Browse the repository at this point in the history
ci: added `--use-uv` option to install dependencies during test-time
  • Loading branch information
15r10nk authored Dec 22, 2024
2 parents bbbe50e + fc23284 commit b28db9c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 16 deletions.
43 changes: 43 additions & 0 deletions changelog.d/20241222_102321_15r10nk-git.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed
- A bullet item for the Removed category.
-->
<!--
### Added
- A bullet item for the Added category.
-->
<!--
### Changed
- A bullet item for the Changed category.
-->
<!--
### Deprecated
- A bullet item for the Deprecated category.
-->
### Fixed

- uv is now only used during test time if you run the inline-snapshot tests with `pytest --use-uv`
This solves a problem if you want to package inline-snapshot in distributions (#165)



<!--
### Security
- A bullet item for the Security category.
-->
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ matrix.pytest.dependencies = [

[tool.hatch.envs.hatch-test]
# Info for everyone who packages this library:
# The following dependencies are installed with uv during the pytest run
# The following dependencies are installed with uv if you run `pytest --use-uv`
# and used for specific tests in specific versions:
# - pydantic v1 & v2
# - attrs
# But you dont have to use uv to test this library.
# You can also just install the dependencies and use `pytest` normally
extra-dependencies = [
"dirty-equals>=0.7.0",
"hypothesis>=6.75.5",
Expand All @@ -126,8 +128,8 @@ extra-dependencies = [
env-vars.TOP = "{root}"

[tool.hatch.envs.hatch-test.scripts]
run = "pytest{env:HATCH_TEST_ARGS:} {args}"
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} {args}"
run = "pytest{env:HATCH_TEST_ARGS:} --use-uv {args}"
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} --use-uv {args}"
cov-combine = "coverage combine"
cov-report=["coverage report","coverage html"]

Expand Down
24 changes: 15 additions & 9 deletions tests/adapter/test_dataclass.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from inline_snapshot import snapshot
from inline_snapshot.extra import warns
from inline_snapshot.testing._example import Example
Expand Down Expand Up @@ -119,7 +120,12 @@ def test_something():
)


def test_attrs_default_value():
@pytest.fixture
def attrs_deps(use_uv):
yield (["attrs"] if use_uv else [])


def test_attrs_default_value(attrs_deps):
Example(
"""\
from inline_snapshot import snapshot,Is
Expand All @@ -138,7 +144,7 @@ def test_something():
"""
).run_pytest(
["--inline-snapshot=fix"],
extra_dependencies=["attrs"],
extra_dependencies=attrs_deps,
changed_files=snapshot(
{
"test_something.py": """\
Expand All @@ -160,7 +166,7 @@ def test_something():
),
).run_pytest(
["--inline-snapshot=update"],
extra_dependencies=["attrs"],
extra_dependencies=attrs_deps,
changed_files=snapshot(
{
"test_something.py": """\
Expand All @@ -183,7 +189,7 @@ def test_something():
)


def test_attrs_field_repr():
def test_attrs_field_repr(attrs_deps):

Example(
"""\
Expand All @@ -199,7 +205,7 @@ class container:
"""
).run_pytest(
["--inline-snapshot=create"],
extra_dependencies=["attrs"],
extra_dependencies=attrs_deps,
changed_files=snapshot(
{
"test_something.py": """\
Expand All @@ -216,11 +222,11 @@ class container:
}
),
).run_pytest(
extra_dependencies=["attrs"],
extra_dependencies=attrs_deps,
)


def test_attrs_unmanaged():
def test_attrs_unmanaged(attrs_deps):
Example(
"""\
import datetime as dt
Expand All @@ -246,10 +252,10 @@ def test():
"""
).run_pytest(
["--inline-snapshot=create,fix"],
extra_dependencies=["attrs"],
extra_dependencies=attrs_deps,
changed_files=snapshot({}),
).run_pytest(
extra_dependencies=["attrs"],
extra_dependencies=attrs_deps,
)


Expand Down
23 changes: 22 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,30 @@ def check_pypy(request):
yield


def pytest_addoption(parser):
parser.addoption(
"--use-uv",
action="store_true",
default=False,
help="install different package versions at test time",
)


@pytest.fixture
def use_uv(request):
yield request.config.getoption("--use-uv")


@pytest.fixture(params=["pydantic>=2.0.0", "pydantic<2.0.0"])
def pydantic_version(request):
yield request.param
use_uv = request.config.getoption("--use-uv")

if use_uv:
yield [request.param]
else: # pragma: no cover
if request.param == "pydantic<2.0.0":
pytest.skip()
yield []


@pytest.fixture()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_pydantic():
"""
).run_pytest(
["--inline-snapshot=create"],
extra_dependencies=[pydantic_version],
extra_dependencies=pydantic_version,
changed_files=snapshot(
{
"test_something.py": """\
Expand Down Expand Up @@ -64,7 +64,7 @@ class container(BaseModel):
"""
).run_pytest(
["--inline-snapshot=create"],
extra_dependencies=[pydantic_version],
extra_dependencies=pydantic_version,
changed_files=snapshot(
{
"test_something.py": """\
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_something():
"""
).run_pytest(
["--inline-snapshot=update"],
extra_dependencies=[pydantic_version],
extra_dependencies=pydantic_version,
changed_files=snapshot(
{
"test_something.py": """\
Expand Down

0 comments on commit b28db9c

Please sign in to comment.