def batch_info(tmp_path_factory, worker_id): #If there's only 1 thread, it's called master if worker_id == "master": my_batch_info = BatchInfo("Pytest Batch") yield my_batch_info root_tmp_dir = tmp_path_factory.getbasetemp().parent my_batch_info = BatchInfo("Pytest Batch") fn = root_tmp_dir / "data.json" with FileLock(str(fn) + ".lock"): if fn.is_file(): my_batch_info.with_batch_id(int(json.loads(fn.read_text()))) else: batchId = random.randint(0, 999999) my_batch_info.with_batch_id(batchId) fn.write_text(json.dumps(str(batchId))) yield my_batch_info
def create_batch_info( self, name, # type: Text started_at=None, # type: Optional[Union[datetime,Text]] batch_sequence_name=None, # type: Optional[Text] batch_id=None, # type: Optional[Text] ): # type: (...) -> Text """ Returns a BatchInfo ID string that may be used as batch argument on `Eyes Open`. | =Arguments= | =Description= | | Name | The name of the batch | | Started At | The date and time that will be displayed in the Test Manager as the batch start time *(*)* | | Batch ID | This argument groups together tests ran in different executions | The *Started At* argument may be passed as: - String: YYYY-mm-dd HH:MM:SS - Datetime variable: See [https://robotframework.org/robotframework/latest/libraries/DateTime.html|DateTime library] *Example:* | ${batch_id}= | Create Eyes Batch | """ if started_at: if isinstance(started_at, basestring): started_at = datetime.strptime(started_at, "%Y-%m-%d %H:%M:%S") elif not isinstance(started_at, datetime): raise TypeError( "BatchInfo started_at should be `str` or `datetime`") batch = BatchInfo(name, started_at=started_at, batch_sequence_name=batch_sequence_name) if batch_id: batch = batch.with_batch_id(batch_id) self.ctx.register_or_get_batch(batch) return batch.id