Skip to content
Advertisement

Tag: pytest

How to pytest that a decorator is assigned to multiple functions

I read somewhere on SO that you should not test the decorator but the functionality of the wrapped function. Nevertheless there might be a shorter way of testing whether a certain decorator is assigned to multiple functions. I have this decorator: I have some tests to test the decorator function itself, e.g.: Now I have about 20 FastAPI endpoints where

unit testing with pytest parametrize

I have the following test code: This is not my real test this is just a minimal reproduce example. I need to parameterised only the input which is checked against the same code. For some reason this doesn’t work I always get: How can I fix it? Answer You can’t use @pytest.mark.parametrize on unittest.TestCase methods. PyTest has no way to

Tests being run from imported class

I have a base class with some tests similar to this: And another class that reuses the testing logic within TestA but providing different data: Note that I am doing this and not simply creating another test in TestA because they each test a different class A and B (though the classes have the same interface) The problem I am

Refactoring Test Logic in Pytest to Avoid Complex Raises Block

I’m using the flake8-pytest-style plugin and it flags a certain test as violating PT012. This is about having too much logic in the raises() statement. The code in question is this: Basically this is testing the following code: What I do is just pass in a version of Python that is less than the required and make sure the error

Flask testing with pytest, ENV is set to production?

I have built a flask app and i would like to create a test suite. Reading around it looks like pytest is the way to go; however, I am finding it very difficult to understand how to get going, I have looked at https://flask.palletsprojects.com/en/2.0.x/testing/ but am struggling to relate it to my app. my project has a run.py at its

patch object spawned in sub-processs

I am using multiprocessing package for crating sub-processes. I need to handle exceptions from sub-process. catch, report, terminate and re-spawn sub-process. I struggle to create test for it. I would like to patch object which represent my sub-process and raise exception to see if handling is correct. But it looks like that object is patched only in main process and

Advertisement