I have a pytest file which requires environment being set. So I add the following decorator on every function. Is it a way to skip all the test instead of decorating each test function? BTW, it just skip the tests with the following message. Is it a way to display a warning information of missing environment variable? Answer You can
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
Issues setting up python testing in VSCODE using pytest
I am trying to use the testing extension in VSCode with the Python extension. I am using pytest as my testing library. My folder structure looks like this: In the test_main.py file I am trying to import the package code, in order to test it: From the command line, in the root directory, PACKAGENAME, I can use the command python
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
Why do I need to introduce the arguments when importing the functions of one file
I have a program (file1.py) with functions and I want to test these functions from the file test1.py. When I import the first function I don’t know why the terminal tells me that I need to introduce the arguments that are required when I run file1.py. Is beyond my understanding why this happens because as far as I know from
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
How to terminate a Uvicorn + FastAPI application cleanly with workers >= 2 when testing with pytest
I have an application written with Uvicorn + FastAPI. I am testing the response time using PyTest. Referring to How to start a Uvicorn + FastAPI in background when testing with PyTest, I wrote the test. However, I found the application process alive after completing the test when workers >= 2. I want to terminate the application process cleanly at
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