Skip to content

Tag: pytest

customize html table of pytest with docstring of the test

I have a pytest test function as below. I’d like to print this test_mytest.docstring in the html report as a column between test and duration columns. I could gather that the pytest_runtest_makereport() pytest.mark.hookwrapper could help. Is there any code snippets that I can use as a reference to make the modification Answer Fortunately the exact example is mention in the

How to use pytest fixture with fixture factory?

In scikit-learn, there is a function parametrize_with_checks() that is used as a pytest fixture factory–it returns a pytest.mark.parametrize fixture, and is called as a decorator with an iterable of estimators, e.g. My issue is that my list of estimators may change (or I may have multiple lists), and each list I am setting up in a fixture. Here is a

How to define a mock object inside a mock in python?

I have a class that contains another class in a variable. Now I want to write a unit-test and define a mock object. Therefore I define a fixture in and monkeypatch it with the mock object. I now get a the desired mock object but the inner object is noch the mock object which I defined. The problem ist

Python mocking table schema

I have a simple python function that needs tested that looks like this: However, to test this, I don’t want to test with a real table – I would like to create a Mock schema within my test (and a mock client too). My test currently looks like this: However, when I print returned_schema, I get the following: <MagicMock name=’Client.get_table().schema’

Parametrizing fixtures and functions without combinations

Here’s the thing: I have an Array2D class that receives parameters ‘shape’ and ‘val’. The constructor is as follows: I would like to perform tests on this class. To do this I have declared a variable ARRAY_CONFIG, which lists parameters for different two-dimensional arrays. Here is an example: I have also defined other lists that store the expected values for

pytest throws exception while using ClickArguments SystemExit: 0

I am trying to run a test case for a python script. Test case is successful when I don’t use Click decorator and argument in python script method. But when I am using it, it gives SystemExit: 0. tests/ When I run the test case: then the test fails with: The full output is: Answer Don’t run click commands

Load existing data catalog programmatically

I want to write pytest unit test in Kedro 0.17.5. They need to perform integrity checks on dataframes created by the pipeline. These dataframes are specified in the catalog.yml and already persisted successfully using kedro run. The catalog.yml is in conf/base. I have a test module in src/tests/pipelines/my_pipeline/. How can I load the data catalog based on my catalog.yml

pytest is not running to pick up custom command args

In a project im working on we have a step where we export a csv before exporting we run a regression test step against the report using pytest. pytest is invoked using the following command –sample and –expectations are custom args defined in the using the following when calling this code locally it works pytest finds the conf but

Mocking sqlobject function call for test db

I am trying to mock sqlbuilder.func for test cases with pytest I successfully mocked sqlbuilder.func.TO_BASE64 with correct output but when I tried mocking sqlbuilder.func.FROM_UNIXTIME I didn’t get any error but the resulted output is incorrect with the generated query. Below is the minimal working example of the problem. Current SQL: Expected SQL: Edit Example Answer By default,