Hacker News new | ask | show | jobs
by nsdarren 1860 days ago
Author of Ward here! Thanks for the feedback. It's a common piece of feedback I hear and I do agree.

I haven't documented this yet, but due to the way Ward works you can actually write your tests inside a loop in order to parameterise them (see below). This is a little more explicit, and lets you build up your test data using things like itertools (if you like):

  for lhs, rhs, res in [
      (1, 1, 2),
      (2, 3, 5),
  ]:
      @test("simple addition")
      def _(left=lhs, right=rhs, result=res):
          assert left + right == result

I'm considering how/whether to add a pytest style decorator for parameterisation too.

If you give Ward a try or just have any other general feedback, please let me know if you have any issues/suggestions on GitHub.

2 comments

How do you represent the test ID for complex arguments? In Pytest, that's easily done with `pytest.param`:

    @pytest.parametrize("a,b", [
        pytest.param(..., id="thing1"),
        pytest.param(..., id="thing2"),
    ])
    def test_foo(a, b):
        ...
Probably the closest thing would be to add a unique tag to each instance of the test:

  for lhs, rhs, res, tag in [
        (1, 1, 2, "thing1"),
        (2, 3, 5, "thing2"),
        (3, 4, 7, "thing3"),
  ]:
      @test("simple addition", tags=[tag])
        def _(left=lhs, right=rhs, result=res):
          assert left + right == result
You can then select individual tests using something like `ward --tags thing2` to only run tests with that tag (in my example, the 2nd of 3 tests).

Since multiple tests can share the same tag in Ward, if you wanted to narrow things down to ensure you're only selecting from the tests generated in this loop you could do something like `ward --search 'simple addition' --tags thing2`.

You can also select multiple instances at once with `ward --tags 'thing1 or thing3'`.

FWIW I think this interface is slightly nicer than the pytest one https://pypi.org/project/parameterized/