Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The Shuttle is now going five times the sound of speed. -- Dan Rather, first landing of Columbia


devel / comp.lang.python.announce / [Python-announce] pytest-when 1.0.3

SubjectAuthor
o [Python-announce] pytest-when 1.0.3Artem Zhukov

1
[Python-announce] pytest-when 1.0.3

<78B96914-FB6A-41A1-821B-29D660FD28CA@zhukovgreen.pro>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10019&group=comp.lang.python.announce#10019

  copy link   Newsgroups: comp.lang.python.announce
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: iam...@zhukovgreen.pro (Artem Zhukov)
Newsgroups: comp.lang.python.announce
Subject: [Python-announce] pytest-when 1.0.3
Date: Fri, 19 May 2023 18:38:19 +0200
Lines: 40
Approved: python-announce-list@python.org
Message-ID: <78B96914-FB6A-41A1-821B-29D660FD28CA@zhukovgreen.pro>
Reply-To: python-list@python.org
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\))
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: base64
X-Trace: news.uni-berlin.de g8Lfr5kXhvwmkMRvTimufQwZHfvtwwkGZrsZhyjcXoqQ==
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=zhukovgreen.pro header.i=@zhukovgreen.pro
header.b=TTELu65j; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'engineer': 0.02; 'url-
ip:140.82/16': 0.03; 'def': 0.04; 'pytest': 0.05; 'subject:when':
0.07; 'readable': 0.09; 'received:pro': 0.09; 'skip:` 20': 0.09;
'skip:z 20': 0.09; 'subject:pytest': 0.09; 'to:addr:python-
announce-list': 0.09; 'url:github': 0.14; 'announce': 0.15; 'url-
ip:140/8': 0.15; '"not': 0.16; '-&gt;': 0.16; 'assert': 0.16;
'developer': 0.16; 'all,': 0.20; 'feedback': 0.23; 'behavior':
0.26; 'function': 0.27; 'dir="ltr"': 0.31; 'but': 0.32; 'skip:"
20': 0.34; 'complex': 0.35; 'skip:2 20': 0.35; "we're": 0.35;
'class': 0.37; 'define': 0.40; 'skip:o 10': 0.61; 'arial,': 0.62;
'experience': 0.64; 'received:116': 0.64; 'skip:t 20': 0.66;
'skip:t 30': 0.67; 'helvetica,': 0.69; 'natural': 0.69; 'skip:w
20': 0.69; 'skip:k 20': 0.78; 'href=""': 0.84; 'return.': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zhukovgreen.pro;
s=dkim; t=1684514320; h=from:subject:date:message-id:to:mime-version:content-type;
bh=WA5y+pT01lMMBTMjiOSY5G+Zhe74hqrloTwDNMQfoks=;
b=TTELu65j+ZCcl6Xw6BVrwESUaJmD1oa/2Tbffa8ju9Qk8TbPcwFUD85/OvrgBQvrJsfp6E
5RjsDaXUXEwfoNTRz0hg9xhpIyx5TZtHsnWAai10DPHJZ0dhoi6znaHog8gLx+WvD9Mln0
wVnGCbTJXxG1ADrefVIE/pfQwpT6ZgvkLUNyN1YSS7ipJ4u2H6h7mrWvHCNbA3CBpQ4J+f
W/7nosnBI1ZzLUhFFBwNw+Bpl9n3o3ELW8gEMTOaF6qqeJkS0fOtTaMxgjKjrpwB35peFS
WdggOq5fC8lMwfBEIEmMsYR1hdtBCo3Khs6QCnJ8p7KPBhfgEE0dWfNu6aR5GA==
X-Last-TLS-Session-Version: TLSv1.2
X-MailFrom: iam@zhukovgreen.pro
X-Mailman-Rule-Hits: emergency
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved
Message-ID-Hash: EU2SW7BDKQRGCQSELHPPDJALFRUT2DCZ
X-Message-ID-Hash: EU2SW7BDKQRGCQSELHPPDJALFRUT2DCZ
X-Mailman-Approved-At: Fri, 19 May 2023 12:58:26 -0400
X-Content-Filtered-By: Mailman/MimeDel 3.3.9b1
X-Mailman-Version: 3.3.9b1
Precedence: list
List-Id: Announcement-only list for the Python programming language <python-announce-list.python.org>
Archived-At: <https://mail.python.org/archives/list/python-announce-list@python.org/message/EU2SW7BDKQRGCQSELHPPDJALFRUT2DCZ/>
List-Archive: <https://mail.python.org/archives/list/python-announce-list@python.org/>
List-Help: <mailto:python-announce-list-request@python.org?subject=help>
List-Owner: <mailto:python-announce-list-owner@python.org>
List-Post: <mailto:python-announce-list@python.org>
List-Subscribe: <mailto:python-announce-list-join@python.org>
List-Unsubscribe: <mailto:python-announce-list-leave@python.org>
 by: Artem Zhukov - Fri, 19 May 2023 16:38 UTC

Hi all,
happy to announce a better developer experience with pytest-when fixture.
With pytest-mock you can define the complex mocking behavior via natural interface:
```
when(some_object, "attribute").called_with(1, 2).then_return("mocked")
```
In this case the some_object.attribute(1, 2) == "mocked". But if it will be called with any other
arguments, it will return what it is suppose to return.

Project GitHub:
https://github.com/zhukovgreen/pytest-when
zhukovgreen/pytest-when: Pytest plugin for more readable mocking
github.com
Support python>=3.8 and tested until 3.11

Small example from the docs:
# class which we're going to mock in the test
class Klass1:
def some_method(
self,
arg1: str,
arg2: int,
*,
kwarg1: str,
kwarg2: str,
) -> str:
return "Not mocked"

def test_should_properly_patch_calls(when):
when(Klass1, "some_method").called_with(
"a",
when.markers.any,
kwarg1="b",
kwarg2=when.markers.any,
).then_return("Mocked")
assert (
Klass1().some_method(
"a",
1,
kwarg1="b",
kwarg2="c",
)
== "Mocked"
)
assert (
Klass1().some_method(
"not mocked param",
1,
kwarg1="b",
kwarg2="c",
)
== "Not mocked"
)
# if you need to patch a function
def test_patch_a_function(when):
when(example_module, "some_normal_function").called_with(
"a",
when.markers.any,
kwarg1="b",
kwarg2=when.markers.any,
).then_return("Mocked")
assert (
example_module.some_normal_function(
"a",
1,
kwarg1="b",
kwarg2="c",
)
== "Mocked"
)
assert (
example_module.some_normal_function(
"not mocked param",
1,
kwarg1="b",
kwarg2="c",
)
== "Not mocked"
)

Thank you for any feedback
--
zhukovgreen,
Data Engineer @Paylocity
https://github.com/zhukovgreen


devel / comp.lang.python.announce / [Python-announce] pytest-when 1.0.3

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor