TGViewer
Находки в опенсорсе Находки в опенсорсе @opensource_findings · 12.6K subscribers
Post #841 7.06K
И сразу пример нового контента.

За последние два дня добавил поддержку двух новых типов в hypothesis:
- ReadOnly: https://github.com/HypothesisWorks/hypothesis/pull/4072
- LiteralString: https://github.com/HypothesisWorks/hypothesis/pull/4075

Что такое hypothesis? Такой фреймворк для тестирования на основе идеи Property-Based Testing: когда вы тестируете не конкретные значения, а целые законы или свойства вашей системы.

Например:


import datetime as dt

import attrs

@attrs.define
class User:
# ...
joined_at: dt.datetime
last_loggined_at: dt.datetime

def create_our_user() -> User:
... # your business logic

# Testing:
from hypothesis import given, strategies as st

@given(st.builds(create_our_user))
def test_user_login_cannot_be_after_created(user: User) -> None:
assert user.last_loggined_at >= user.joined_at


Что очень удобно, st.from_type(...) может просто по аннотациям генерировать вам объекты; потому поддержка новых типов - всегда полезна.

Hypothesis является частью CI самого CPython: https://github.com/python/cpython/blob/main/Lib/test/support/hypothesis_helper.py и является очень крутой технологией.

На ее основе можно делать безумные вещи: https://sobolevn.me/2021/02/make-tests-a-part-of-your-app
GitHub GitHub - HypothesisWorks/hypothesis: The property-based testing library for Python The property-based testing library for Python. Contribute to HypothesisWorks/hypothesis development by creating an account on GitHub.
  • 👍 36
  • 😱 8
  • 🔥 3
More from @opensource_findings
  1. Sep 28, 2026Еще анонсы докладов на бесплатную конференцию 17 октября в НН Регистрация: https://itgorky…
  2. Sep 25, 2026Монадические выражения в Python. Наконец-то! Продолжаем разговор про интересные PEPы. Пого…
  3. Sep 15, 2026PEPы в Python окончательно вышли из-под контроля Давайте посмотрим, что происходит с ПЕПам…
  4. Sep 10, 2026Большая бесплатная конференция в Нижнем Новгороде 17 октября Регистрация: https://itgorky.…
  5. Sep 1, 2026Post #985
  6. Aug 24, 2026JIT могут удалить из CPython! PEP-836: https://peps.python.org/pep-0836 JIT в CPython имее…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →