Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As someone that loves Python and hates pytest, you have my support.

(Although, I don't like using bare `assert`s in tests, but maybe you'll convince me.)



Thanks for the support! It means a lot, especially from someone who shares the pytest frustration.

About bare `assert`s. Vedro is actually flexible enough to use any matchers you prefer, but let me share why I stick with plain asserts:

1. In most editor themes, `assert` jumps out with distinct syntax highlighting. When scanning tests, I can quickly spot the assertions and understand what's being tested.

2. The expressions feel cleaner to me:

   assert error_code not in [400, 500]
   # vs
   assert_that(error_code, is_not(any_of(400, 500)))  # hamcrest
3. I like that there's nothing new to learn, the expressions work exactly like they do in any Python code, with no special test behavior or surprises.

Would love to hear what specifically bothers you about bare asserts, always looking to understand different perspectives on testing ergonomics!


Your first and second points makes sense. They don't matter much to me, but I see how others could value those things.

Aside: I also don't like the hamcrest syntax. I also don't love unittest's syntax but it's OK and it's pervasive (i.e., available in the stdlib).

The third point is where I start to disagree more strongly.

> I like that there's nothing new to learn, the expressions work exactly like they do in any Python code, with no special test behavior or surprises.

This doesn't seem true to me.

> the expressions work exactly like they do in any Python code

Not to my mind. In normal Python, an assertion communicates something that is unequivocally believed to be true, not something that may or may not be true (a test). Let me see if I can explain it this way, I often use asserts in tests to show (and enforce) something that I believe to be true and must be true, before the test can have any meaning. E.g.,

assert test_condition() == False invoke_the_code_under_test() self.assertTrue(test_condition())

The "assert" communicates that this is a precondition, the "self.AssertTrue" communicates that this is a test.

I can 100% see that others might not see/care about the distinction, but I think it is important.

> no special test behavior

Well, that's not quite true. You have to handle the AssertionError specially and do some fairly magical work to figure out the details of the expression that failed. The unittest-style assertions just report the values passed into them.

I don't really like that magic, both from an aesthetic standpoint and from a least-complexity-in-my-tooling standpoint. Again, I can understand others making different tradeoffs.


Thank you for taking the time to explain your perspective, this is exactly the kind of thoughtful feedback that helps me understand different testing philosophies.

Your distinction between assertions (preconditions/invariants) vs tests (things being verified) is really interesting. I can absolutely see how using different syntax helps communicate intent: "this MUST be true for the test to even make sense" vs "this is what we're actually testing". That semantic clarity is valuable, it reminds me of contract programming in languages like D where preconditions and postconditions have distinct roles.

You're absolutely right about the special assertion handling, that's definitely special behavior and I should have been clearer. What I meant was that the expressions themselves evaluate using Python's normal rules without hidden transformations. For example, Playwright's `expect(loc).to_have_text("text")` silently normalizes whitespace, so "hello world" might match "hello world". With plain asserts, `assert element.text == "hello world"` means exactly that: no normalization, no special matching rules. The expression evaluates the same way it would in a REPL.

But yes, extracting the failure details does require machinery that I'm not thrilled about either. It's the one compromise I made to support the plain assert syntax that many Python developers expect. But actually, you can use the `asserts` helper which does exactly what you described without any special handling:

  from vedro import scenario, asserts as _
  
  @scenario
  def calculate_discount():
      product = ...
      
      discounted = apply_discount(product, 0.2)
      
      _.assert_equal(discounted.price, 80.0)


I appreciate the consideration. I'll be watching Vedro with interest.

I do like the nicer vedro.asserts mechanism. If that works with unittest and pytest it would be really nice. You might get a few converts that way, too.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: