testing

Using pytest to reuse the same dataframe across modules in a class

Using pytest to reuse the same dataframe across modules in a class Question: I am trying to reuse the same dataframe in pytest. I have initialised it in the init method but I would like to change it into a pytest fixture then pass it through to each of the methods. I am struggling to …

Total answers: 1

Optimize function's parameters with conditions (python)

Optimize function's parameters with conditions (python) Question: I begin by saying that I am totally new to this branch of programming, but i think that scipy optimization could be the solution. I need to find the parameters that return the highest result in a function, but only if the result respect a condition. The function …

Total answers: 1

Pytest –doctest-modules executes scripts

Pytest –doctest-modules executes scripts Question: I have this MRE: . └── tests └── notest.py The notest.py just do a sys.exit(1): When I run pytest –doctest-modules I get this error: ERROR collecting tests/notest.py tests/notest.py:4: in <module> sys.exit(1) E SystemExit: 1 So the –doctest-modules would try to execute my script which is not a test. Is that …

Total answers: 1

Pytest tries to collect wrong classes

Pytest tries to collect wrong classes Question: I have a Python module: . ├── module │ ├── __init__.py │ ├── __main__.py │ └── suite.py ├── docs ├── pyproject.toml ├── pytest.ini ├── setup.cfg ├── setup.py ├── tests │ ├── test_config.py │ ├── test_description.py │ ├── test_id.py │ ├── foo.py │ └── test_schema.py └── tox.ini When I …

Total answers: 1

JSON value is converted to unicode – python

JSON value is converted to unicode – python Question: My current Python Appium test automation framework reads data from JSON file using the json.load() The value "Ελλάδα" stored in JSON is converted to "Ελλάδα" when json.load() method is called. Pleases point me to a solution were I can maintain the the actual string value "Ελλάδα" …

Total answers: 1

A random seed that makes tests fail the same way every time?

A random seed that makes tests fail the same way every time? Question: I’ve never worked with the random library and I’m a bit confused about what this fixme statement is asking me to do. Is there a seed number that specifically does this? The code is making an ordered list ADT and this file …

Total answers: 3

Infinite loop testing

Infinite loop testing Question: How could I test an infinite loop? For example: func.py def func(): while True: char = input().lower() if char == ‘q’: break elif char.isalpha(): print("It’s not a number") if int(char) == #some_number break else: print(‘Try again’) test.py def test_func(): ??? Is there any solution for testing this? Asked By: user20234729 || …

Total answers: 1

Test assert function order with mocks (pytest -> assert_has_calls)

Test assert function order with mocks (pytest -> assert_has_calls) Question: I’m trying to test the order of the sub-functions inside of the main function: def get_data(): pass def process_data(data): pass def notify_admin(action): pass def save_data(data): pass def main_func(): notify_admin(‘start’) data = get_data() processed_data = process_data(data) save_data(processed_data) notify_admin(‘finish’) I’m using pytest, so far I’ve come up …

Total answers: 1

Python unit-testing a complicated method

Python unit-testing a complicated method Question: I am looking for any advice on how to unit test the following method. def delete_old_files(self): """Deletes all recordings older then a predefined time period. Checks the mtime of files in _store_dir and if it is older then the predefined time period delete them. """ now = time.time() self.logger.info( …

Total answers: 1

Parametrizing fixtures and functions without combinations

Parametrizing fixtures and functions without combinations Question: Here’s the thing: I have an Array2D class that receives parameters ‘shape’ and ‘val’. The constructor is as follows: class Array2D: … def __init__(self, shape: tuple, val): self.shape = shape self.size = self.shape[0] * self.shape[1] self.data = [val] * self.size … I would like to perform tests on …

Total answers: 1