Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer's execution order #4

Closed
tiho44 opened this issue Oct 30, 2023 · 1 comment
Closed

Analyzer's execution order #4

tiho44 opened this issue Oct 30, 2023 · 1 comment

Comments

@tiho44
Copy link

tiho44 commented Oct 30, 2023

Hey Oleksii, small q from our side regarding artifacts:

we upload artifacts during fixture teardown. meaning testomatio_artifacts would not be ready on pytest_runtest_makereport call.when == 'call'

execution order, in our scenario:

  1. pytest_runtest_makereport call=setup
  2. pytest_runtest_makereport call=run
  3. analyzer posts test report
  4. fixture teardown (artifacts uploaded)

know you enabled s3_connector, but unfortunately it's not the way for us since fixtures have their own dependencies

this is the quick ugly patch that works for us:

def pytest_runtest_makereport(item: Item, call: CallInfo):
    global analyzer_config_option
    analyzer_config_option = item.config.getoption(analyzer_option)
    if analyzer_config_option is None or analyzer_config_option != 'sync':
        return
    elif not pytest.analyzer_test_run_config.test_run_id:
        return
    
    global request
    if call.when == 'setup':
        test_item = TestItem(item)
        request = {
            'status': None,
            'title': test_item.title,
            'run_time': None,
            'suite_title': test_item.file_name,
            'suite_id': None,
            'test_id': test_item.id[2:] if test_item.id else None,  # remove @T if exists
            'message': None,
            'stack': None,
            'example': None,
            'artifacts': None,
            'steps': None,
            'code': None,
        }
        if call.excinfo is not None:
            if call.excinfo.typename == 'Skipped':
                request['status'] = 'skipped'
            else:
                request['message'] = str(call.excinfo.value)
                request['stack'] = '\n'.join((str(tb) for tb in call.excinfo.traceback))
                request['status'] = 'failed'
        log.warning("setup req: %s", request)
    if call.when == 'call':
        request['run_time'] = call.duration
        if call.excinfo is not None:
            request['message'] = str(call.excinfo.value)
            request['stack'] = '\n'.join((str(tb) for tb in call.excinfo.traceback))
            request['status'] = 'failed'
        else:
            request['status'] = 'passed'
        if hasattr(item, 'callspec'):
            example = item.callspec.params
            if type(example) is bytes:
                request['example'] = example.decode('utf-8')
            elif type(example) in (str, int, float, bool):
                request['example'] = item.callspec.params
            else:
                request['example'] = 'object'  # to avoid json serialization error
        log.warning("call req: %s", request)
    if call.when == 'teardown':
        request['artifacts'] = getattr(item, 'testomatio_artifacts', None)
        log.warning("teardown req: %s", request)


def pytest_runtest_logfinish(nodeid, location):
    if analyzer_config_option is None or analyzer_config_option != 'sync':
        return
    elif not pytest.analyzer_test_run_config.test_run_id:
        return
     
    global request
    log.warning("Running logfinish: %s", request)
    if request['status']:
        log.warning("Uploading with status: %s", request['status'])
        connector = pytest.connector
        connector.update_test_status(run_id=pytest.analyzer_test_run_config.test_run_id, **request)
        for key,_ in request.items():
            request[key] = None

can this be done? i'm sure you have better ideas. thanks for your help.

Ypurek pushed a commit that referenced this issue Dec 6, 2023
@Ypurek
Copy link
Collaborator

Ypurek commented Dec 6, 2023

sorry for the delay - just introduced changes you've requested

@Ypurek Ypurek closed this as completed Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants