How do you test a mutable, implied result?

GIS-Jonathan

I have a function that doesn't "return" anything but relies on altering a dictionary/list using its mutability. i.e.:

def func(my_list):
    my_list.append(4)

I want to test this function using pytest and parameterisation:

@pytest.mark.parametrize("input1, result", [
    ([1], [1, 4]),
    ([33, 44], [33,44, 4])
])
def test_mytest(input1, result):
    assert func(input1) == result

Problem is, this obviously won't work because my function doesn't actually "return" my_list. Is it possible to test the value of my_list using pytest, and if so how?

deborah-digges

You could compare the value of list1 to result after the call to the function.

def test_mytest(input1):
    func(input1)
    assert input1 == result

Note that input1 will be modified after the call to the function and can now be compared to the expected result

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do you test functions that return Result?

From Dev

How do you borrow a mutable pointer in rust?

From Dev

How do you borrow a mutable reference during a match?

From Dev

How do you test a Gmail Contextual Gadget?

From Java

How do you unit test private methods?

From Dev

How do you test for NaN in JavaScript?

From Java

How do you test for a specific Rust error?

From Java

How do you skip a unit test in Django?

From Dev

How do you test an enum flag combination?

From Dev

How do you test if an exception is thrown in Flutter?

From Dev

How do you test your database design?

From Dev

How do you test the identity of Strings in Swift?

From Dev

How do you inject a repository into a test?

From Dev

How do you Bulk Test URL Redirections?

From Dev

How do you test certificate pinning with Alamofire?

From Dev

How do you Bulk Test URL Redirections?

From Dev

How do you test the value of charAt(0)?

From Dev

How do you achieve a stress test in Gatling?

From Dev

How do you use test-unit?

From Dev

How do you test that an Iterator/ListIterator works?

From Dev

How do you test an iOS framework

From Dev

Formatted reads and implied do

From Dev

How do you return a boolean value based on the result of a promise?

From Dev

In Mule how do you repeatedly call a webservice and return an aggregate of the result?

From Dev

how do you get the similar result computed with dlply using dplyr?

From Dev

How do you search through a hash mapped from an ActiveRecord result?

From Dev

Java Transformer: How do you make its result into an OutputStream?

From Dev

How do you run a function on the result of NgFor in Angular2?

From Dev

Perl how do you assign a varanble to a regex match result

Related Related

HotTag

Archive