Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock an attr.ib validator

I have an attrs class:

@attr.s    
class Example:
    my_int = attr.ib(validator=attr.validator.instance_of(MyComplexType))

I need to mock this validator.

like image 201
zhukovgreen Avatar asked Dec 05 '25 04:12

zhukovgreen


1 Answers

Since everything after initialization is baked and immutable, mocking is not gonna work I think. However you you can temporarily disable validators using attr.set_run_validators().

like image 178
hynek Avatar answered Dec 07 '25 20:12

hynek