Recursive unittest discover

In doing a bit of digging, it seems that as long as deeper modules remain importable, they’ll be discovered via python -m unittest discover. The solution, then, was simply to add a __init__.py file to each directory to make them packages. . ├── LICENSE ├── models │   └── __init__.py ├── README.md ├── requirements.txt ├── tc.py … Read more

Python mock call_args_list unpacking tuples for assertion on arguments

I think that many of the difficulties here are wrapped up in the treatment of the “call” object. It can be thought of as a tuple with 2 members (args, kwargs) and so it’s frequently nice to unpack it: args, kwargs = call Once it’s unpacked, then you can make your assertions separately for args … Read more

patching a class yields “AttributeError: Mock object has no attribute” when accessing instance attributes

No, autospeccing cannot mock out attributes set in the __init__ method of the original class (or in any other method). It can only mock out static attributes, everything that can be found on the class. Otherwise, the mock would have to create an instance of the class you tried to replace with a mock in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)