Source code for schrodinger.test.test_markers

"""
Container for test marker functions. These can be used to mark functions,
methods, or classes.
"""

import socket
import subprocess
import sys

import pytest

from schrodinger import gpgpu
from schrodinger.infra.test import product_installed
from schrodinger.utils.sysinfo import is_display_present
from schrodinger.utils import mmutil
from schrodinger.utils import platform

display_present = is_display_present()

not_linux = pytest.mark.skipif(sys.platform.startswith('linux'),
                               reason='Not supported on Linux')
not_darwin = pytest.mark.skipif(sys.platform == 'darwin',
                                reason="Not supported on MacOS (darwin)")
not_windows = pytest.mark.skipif(sys.platform == 'win32',
                                 reason="Not supported on Windows")
not_windows32 = pytest.mark.skipif(sys.platform == 'win32' and
                                   sys.maxsize <= 2**32,
                                   reason="Not supported on 32 bit Windows")
not_windows64 = pytest.mark.skipif(sys.platform == 'win32' and
                                   sys.maxsize > 2**32,
                                   reason="Not supported on 64 bit Windows")
require_gpu = pytest.mark.skipif(not gpgpu.is_any_gpu_available(),
                                 reason="No GPU available")
require_legacy_jobcontrol = pytest.mark.skipif(
    mmutil.feature_flag_is_enabled(mmutil.JOB_SERVER),
    reason="Not supported with JOB_SERVER")
require_job_server = pytest.mark.skipif(
    not mmutil.feature_flag_is_enabled(mmutil.JOB_SERVER),
    reason="Requires JOB_SERVER")

require_display = pytest.mark.require_display
slow = pytest.mark.slow
post_test = pytest.mark.post_test


def _is_m1():
    """
    Check whether we're running m1. Should only be called once to set `IS_M1`.
    """
    if sys.platform != platform.DARWIN:
        return False
    uname = subprocess.check_output(['uname', '-m'],
                                    universal_newlines=True).strip()
    if uname == 'arm64':
        return True
    elif uname == 'x86_64':
        # Might be an M1 running under Rosetta
        m1_check = ['sysctl', '-in', 'sysctl.proc_translated']
        res = subprocess.check_output(
            ['sysctl', '-in', 'sysctl.proc_translated'],
            universal_newlines=True).strip()
        return res == '1'


IS_M1 = _is_m1()


[docs]def skip_m1(reason): return pytest.mark.skipif(IS_M1, reason=reason)
[docs]def xfail_m1(reason): return pytest.mark.xfail(IS_M1, reason=reason)
[docs]def is_current_mac_builder(): """ Return True if the up-to-date mac builder which tracks all current xcode updates. """ return "pdx-current-m01" in socket.gethostname()
skip_noninteractive_osx_current = pytest.mark.skipif( is_current_mac_builder, reason= "PANEL-11702 causes hang in processEvents without mouse/keyboard movement")
[docs]def require_product(product_name): """ A test requires a specific product. Automatically adds the following: * Test is a post test (must be run with --post-test or --post-test-only) * Test will be skipped if `product_name` is not installed. * Test is marked with "require_{product_name}", and can be selected like -m require_{product_name}, for example -m require_psp """ def marker(obj): markers = [ post_test, pytest.mark.skipif(not product_installed(product_name), reason=f'Requires {product_name}'), getattr(pytest.mark, f'require_{product_name}') ] for _marker in markers: obj = _marker(obj) return obj return marker