News for hackers. Stuff that matters.
Re:Show HN: Python Tests That Write Themselves by kburman on Wednesday September 18, 2019 @07:48AM (#21004288)
Nice concept but does it work with real-world application. I failed to understand how will it work with methods like `authenticate_user(user)` or `load_permissions_from_db(user, db)`.
Re:Show HN: Python Tests That Write Themselves by timothycrosley on Wednesday September 18, 2019 @11:45AM (#21006564)
Hi @kburman,

For cases like that it would be best combined with a mock:

  @auto_pytest()
  def test_add(test_case, mocker):
      mocker.patch('db.call')
      test_case()
Note that this example utilizes the following pytest extension: https://github.com/pytest-dev/pytest-mock

However, I would also note, that just because you have some methods that have potentially dangerous side effects, in most large code-bases, not all functions do. Which is why it operates at a function by function basis. You can use this for new pure functions, while continuing to write other tests in the same fashion by hand.