I’m using the Hypothesis library for unit testing. With this library you don’t hand-pick inputs, but you define the complete set of inputs for which you want to test. Hypothesis will then sample from this set to look for inputs that break the function. This is also known as property-based testing. In Hypothesis, these sets are called strategies. Now I
Tag: unit-testing
mocking multiprocessing.Process target in unit tests
I want to test if a mocked method is called by multiprocessing.Process. I am aware that a subprocess call makes a fork of the current process and that the information can only be available in the subprocess. However, I would like to know if there is a clean way to test such a usecase anyway. One possibility would certainly be
Gitlab CI/CD Pipeline Runs Django Unit Tests Before Migrations
Problem I’m trying to set up a test stage in Gitlab’s CI/CD. Locally, running the unit tests goes fine and as expected. In Gitlab’s CI/CD, though, when running the script coverage run manage.py test -v 2 && coverage report the unit tests are executing before the migrations are completed in the test database, which is unexpected, and will always fail.
How to patch an object instantiated outside of a function to reuse in every test python
I have a module where I instantiate an object outside of my functions, so I can reuse it: I want to patch this client once so that in my tests I can reuse it across multiple tests, like so: The above patch doesn’t work, it runs the tests with the real object instance. How can I correctly patch this in
How to mock functions with same name, when called twice?
How do I mock a function which has been called twice in the same file, with different parameters? Here is my code snippet: code_file.py code_test.py First mock call to graphql is succeeding. The second graphql call is not getting mocked. It is trying to contact the actual server and receiving 404. How can I mock both graphql client calls? Answer
Publish Unit test in Python
I need to publish the result, but could not and have looked through this site and made research but still having issue to publish test result. Do I need to edit certain file similar to the cypress.json to be able to resolve the issue of Publishing. Both Unit test and the coveratge are not publishing any result and files are
TypeError: object is not callable when instantiating during unit test
I have a class that throws an exception when instantiated with wrong values and I would like to write a unit test raising an exception when given wrong parameters. Instantiating an object outside of the self.assertRaises() doesn’t seem to cause any error and I fail to understand why it causes an error when I try to instantiate it within the
Configute tox.ini to ignore library during tests with py27
I have the following tox.ini configuration file: I have update my requirements.txt file in order to upgrade the version of Marshmallow from 3.0.0b14 to 3.10.0; like this: Now my problem is that, when I run tox -e py37 everything works fine, but when I run this command tox -e py27, it fails. I get that the issue is that Marshmallow
How do I mock a file open for a specific path in python?
So I know that in my unit test I can mock a context manager open(), i.e.: mocked with but is there a way for me to only mock it for a specific file path? Or maybe some other way to ensure that the context manager gets called with the correct path in a unit test? Answer To mock open only
Why does python unittest assertRaises method not register exceptions that are thrown?
I have a problem similar to this post, however the solution doesn’t help me as I only pass one argument to the function. I have the following code: which I test using the python unittest module. However, even when my exceptions are raised, the assertions fail. When I run this, the traceback is: As you can see, it printed pass