Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prelim support for test-level markers #5517

Merged
merged 12 commits into from
May 23, 2024
4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

<h3>Improvements 🛠</h3>

* Add support for 3 new pytest markers: `unit_test`, `integration_test` and `system_test`.
[(#5517)][https://github.com/PennyLaneAI/pennylane/pull/5517]
mlxd marked this conversation as resolved.
Show resolved Hide resolved

* The sorting order of parameter-shift terms is now guaranteed to resolve ties in the absolute value with the sign of the shifts.
[(#5582)](https://github.com/PennyLaneAI/pennylane/pull/5582)

Expand Down Expand Up @@ -153,5 +156,6 @@ Soran Jahangiri,
Korbinian Kottmann,
Christina Lee,
Vincent Michaud-Rioux,
Lee James O'Riordan,
Kenya Sakka,
David Wierichs.
2 changes: 2 additions & 0 deletions tests/numpy/test_numpy_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
general_gen = random.default_rng()


@pytest.mark.unit_test
class TestGeneratorDistributions:
@pytest.mark.parametrize("distribution", distributions_no_extra_input)
def test_generator_distributions(self, distribution):
Expand All @@ -61,6 +62,7 @@ def test_generator_distributions(self, distribution):
assert output.requires_grad is False


@pytest.mark.unit_test
class Test_default_rng:
def test_no_input(self):
"""Tests that np.random.default_rng() returns a generator object when
Expand Down
9 changes: 9 additions & 0 deletions tests/numpy/test_numpy_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pennylane.numpy.tensor import tensor_to_arraybox


@pytest.mark.unit_test
class TestExtractTensors:
"""Tests for the extract_tensors function"""

Expand Down Expand Up @@ -56,6 +57,7 @@ def test_iterable_with_unpatched_numpy_arrays(self):
assert res[1] is arr2


@pytest.mark.unit_test
class TestTensor:
"""Tests for the Tensor(ndarray) subclass"""

Expand Down Expand Up @@ -141,6 +143,7 @@ def test_numpy_to_arraybox(self):
]


@pytest.mark.unit_test
class TestNumpyIntegration:
"""Test that the wrapped NumPy functionality integrates well
with standard NumPy functions."""
Expand Down Expand Up @@ -428,6 +431,7 @@ def __call__(self, *args, **kwargs):
assert len(res) == 2


@pytest.mark.integration_test
dwierichs marked this conversation as resolved.
Show resolved Hide resolved
class TestAutogradIntegration:
"""Test autograd works with the new tensor subclass"""

Expand Down Expand Up @@ -458,6 +462,7 @@ def cost(x):
grad_fn(arr1)


@pytest.mark.unit_test
class TestScalarHashing:
"""Test for the hashing capability of scalar arrays."""

Expand Down Expand Up @@ -505,13 +510,15 @@ def test_nonzero_dim_arrays_non_hashable(self):
class TestNumpyConversion:
"""Tests for the tensor.unwrap() and tensor.numpy() methods"""

@pytest.mark.unit_test
def test_convert_scalar_array(self):
"""Test that a scalar array converts to a python literal"""
data = np.array(1.543)
res = data.unwrap()
assert res == data.item()
assert isinstance(res, float)

@pytest.mark.unit_test
def test_convert_array(self):
"""Test that a numpy array successfully converts"""
data = np.array([1, 2, 3])
Expand All @@ -522,6 +529,7 @@ def test_convert_array(self):
assert isinstance(res, np.ndarray)
assert not isinstance(res, np.tensor)

@pytest.mark.system_test
def test_single_gate_parameter(self):
"""Test that when supplied a PennyLane tensor, a QNode passes an
unwrapped tensor as the argument to a gate taking a single parameter"""
Expand All @@ -545,6 +553,7 @@ def circuit(phi=None):
assert op.name == "RX"
assert op.parameters == [p]

@pytest.mark.system_test
def test_multiple_gate_parameter(self):
"""Test that when supplied a PennyLane tensor, a QNode passes arguments
as unwrapped tensors to a gate taking multiple parameters"""
Expand Down
3 changes: 3 additions & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[pytest]
markers =
unit_test: marks tests as unit-level tests (select with '-m "unit_test"')
integration_test: marks tests as integration-level tests (select with '-m "integration_test"')
system_test: marks tests as system-level tests (select with '-m "system_test"')
trbromley marked this conversation as resolved.
Show resolved Hide resolved
mlxd marked this conversation as resolved.
Show resolved Hide resolved
core: marks tests for core testing (select with '-m "core"')
autograd: marks tests for autograd testing (select with '-m "autograd"')
torch: marks tests for torch testing (select with '-m "core"')
Expand Down
Loading