Skip to content
Advertisement

Tag: unit-testing

AssertEqual failing when comparing two seemingly identical IndexErrors

I have a DynamicArray class shown below. (I have only included relevant methods. The rest can be viewed from https://www.geeksforgeeks.org/implementation-of-dynamic-array-in-python/) Then I have another unit test file down below When I run the test I expect self.a.__getitem__(0) to throw IndexError(‘0 is out of bounds’) and I can’t see why the assertion fails? The only difference is that self.a.__getitem__(0) will yield

Mocking FastText model for utest

I am using fasttext models in my python library (from the official fasttext library). To run my u-tests, I need at some point a model (fasttext.FastText._FastText object), as light as possible so that I can version it in my repo. I have tried to create a fake text dataset with 5 lines “fake.txt” and a few words and called It

Mock property method on class

I have the following dataclass: I’d like to change the behavior of qux during testing. I’m aware of PropertyMock, and could write something like: I’d instead like to substitute the property method (undecorated), something like: I’ve tried various combinations of new_callable, new, etc. when creating the patch object, but I’m seeing: Is there a way I can mock out a

Querying the database in a Django unit test

I am creating a web application which has a POST endpoint, that does two things: Saves the POSTed data (a university review) in the database. Redirects the user to an overview page. Here is the code for it: I haven’t yet implemented passing the user data to the endpoint, and that’s why I’m saving everything under the user with pk=1.

Run / Debug a Django application’s UnitTests from the mouse right click context menu in PyCharm Community Edition?

I must emphasize on PyCharm Community Edition which does not have any Django integration (v2016.3.2 at question time). I’ve Googled my problem and (surprisingly,) I did not get any answers, (of course I don’t exclude the possibility that there might be some, be but I just missed them). The question is simple: in PyCharm, one can Run (Debug) an Unit

Advertisement