how can I use fixture to create a mock file of certain size?

I’m doing something like this def test_collection_size(create_fake_file): files = [create_fake_file] size = get_collection_size(files) assert size == 32 create_fake_file fixture should return a mock file of size 32 bytes I did something like this @pytest.fixture def fake_file_content(): # Returns 32 bytes of space return b" " * 32 @pytest.fixture def create_fake_file(fake_file_content): def _create_fake_file(file_path): # Use unittest.mock.mock_open… Read More how can I use fixture to create a mock file of certain size?

Can I skip a test (or mark it as inconclusive) in pytest while it is running?

I am aware of pytest‘s decorators to mark tests as to be skipped (conditionally). However, all those are evaluated before the test starts. I have a couple of tests that require a user interaction (those are not run on CI obivously), and if that interaction is not provided, I would like to mark these tests… Read More Can I skip a test (or mark it as inconclusive) in pytest while it is running?

Why an object instantiated in one Pytest impacts another instantiated in a different Pytest?

I am testing a class that contains a few methods for handling performance counters. It’s a normal Python class: class S3Db: data = {} fs = None s3_path = None def __init__(self, s3_api_key, s3_api_secret, bucket_name, filename, bucket_path=’/’): if s3_api_key != ‘test’: self.fs = s3fs.S3FileSystem(s3_api_key, secret=s3_api_secret) self.s3_path = f’s3://{bucket_name}{bucket_path}{filename}’ self.data = read_json_s3_path(self.fs, self.s3_path) pass def increment_timed_counter(self,… Read More Why an object instantiated in one Pytest impacts another instantiated in a different Pytest?

Why does pytest return a ModuleNotFoundError when trying to import the src folder?

I have a project named unit_testing with 2 subfolders named src/ and tests/. In src there is a file called my_functions.py and in tests I have a file called test_my_functions.py. This is the code in my_functions.py def adding_pos(a, b, c): if a < 0 or b < 0 or c < 0: output = f’function… Read More Why does pytest return a ModuleNotFoundError when trying to import the src folder?

"Regex pattern did not match", even though they should – pytest

I am trying to match the string in this error: for warning in args: if not isinstance(warning, str): with StaticvarExceptionHandler(): raise TypeError(f"Configure.suppress() only takes string arguments. Current type: {type(warning)}") with the one in this pytest test: with pytest.raises( TypeError, match = "Configure.suppress() only takes string arguments. Current type: .*" ): Configure.suppress(‘ComplicatedTypeWarning’, 1) It should match,… Read More "Regex pattern did not match", even though they should – pytest