I have a dummy funtion to try exceptions: def fun(n): try: if n <1: raise ValueError return 1 except: pass In my unit test I use: import unittest class TestFibonnacci(unittest.TestCase): def test_values(self): self.assertEqual(fun(1),1) self.assertRaises(ValueError, fun(-1)) However I’m unable to get an answer I actually get: An exception occurred E…. ERROR: test_values (main.TestFibonnacci) Traceback (most recent ..
While trying to improve code coverage of unit tests in my python flask app I am encountering some code coverage gaps. So there is a 404 error handler @app.errorhandler(404) def page_not_found(e): app.logger.exception(e) if isinstance(e, HTTPException): return e return "404 Page not Found", 404 With this unit test def test_404_check(app, client): res = client.get(‘/testof404’) assert res.status_code ..
I am using firestore with python to write cloud functions. I need to test a function with following query: from google.cloud import firestore MY_COLLECTION_GROUP = firestore.Client(project="my-project").collection_group("my_collection") def function_to_test(data): my_query = ( MY_COLLECTION_GROUP.where("eventDateTime", "==", data["dateTime"]) .where("user.id", "==", data["user_id"]) .where("user.age", ">=", data["valid_age"]) ) # fetch results from query and proceed further To test the above function, I ..
It looks like garbage collection is a problem with python3 -m unittest discover. Look at this example: file: model.py # a basic SQLAlchemy declarative model, as well as the DB manager to insert the data from sqlalchemy.engine import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy import Table, Column, Integer, String from sqlalchemy.ext.declarative import declarative_base Base ..
Firstly, thank you for reading this post. Hopefully, there is an answer out there in the ether. I am using unitest and coding rooms to deliver programming courses for users. I am setting up unitest but getting errors. One of which confuses me is an EOF error which is corresponding to an input command. The ..
I’m writing a library that uses deep neural networks through PyTorch. I need to make sure that the large network architectures we’ve implemented keep working. I’ve implemented this as simple tests: create an input, create a network, pass the input through the network, check that the output has the right shape. Each one of these ..
I have been using PyTest for some time now to write some simple tests (like the ones you find in tutorials and youtube video’s) and I thought now it was time to start writing actual test for our python scripts. The scripts are way more advanced than any shown in tutorials so I am getting ..
Below is a code snippet for which I am trying to write unit tests. I have also copied the unit tests I have written. I am new to unit testing but from what I understand in test_main_version_exception unit test the compare_version.version_match() function would raise an exception and ideally this exception should get caught by the ..
I have to run a test, but for some reason Django doesn’t want to import models. Source: Python..
In unit tests, I’m used to writing def patched_function(): … @patch("package.module.function", new=patched_function) class TestExample: And then any time the code I’m testing calls package.module.function, it instead called patched function. But what if I want to patch an entire class? I know about Mock, but that won’t work because it’s the code I’m testing that’s instantiating ..