testing

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

How can I automate a feature only occurs in android app using Python

How can I automate a feature only occurs in android app using Python Question: I’m trying to automate a feature that only shows in an android app, Is there a way to get it with selenium? Thanks a lot Asked By: Pascal || Source Answers: So the answer is to use Appium and Appium inspector …

Total answers: 1

Error when reverse url with multiple arguments – Django

Error when reverse url with multiple arguments – Django Question: I’m writing a test for an url, problem is it fails when I try to pass multiple arguments, here is some code: #test_urls.py from django.test import SimpleTestCase from django.urls import reverse, resolve from cardiotesting.views import * class TestUrls(SimpleTestCase): def test_new_cardio(id_patient, protocol): id_patient = ’05’ protocol …

Total answers: 2