# MIT License
#
# Copyright (c) 2018 Lotus Engineering, LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

#
# This module contains the test fixtures for pytest
# These fixtures MUST be loaded in your conftest.py file to be used
#
import pytest
from qspypy.qutest import qutest_context
import qspypy.config as CONFIG


@pytest.fixture(scope='session')
def qutest_session():
    """ test fixture for a complete session (all test files)"""

    # Create the one and only qutest_context used through out the session
    context = qutest_context()

    # Do the context setup
    context.session_setup()

    # Yield context to subfixtures to pass along to tests
    yield context

    # Do the context teardown
    context.session_teardown()


@pytest.fixture()
def qutest(qutest_session):
    """ Default test fixture for each test function.

    This will reset the target before each test unless
    the RESET_TARGET_ON_SETUP is set to False
    """

    if CONFIG.RESET_TARGET_ON_SETUP:
        qutest_session.reset_target()

    return qutest_session


@pytest.fixture()
def qutest_noreset(qutest_session):
    """ Test fixture for each test function that does NOT reset the target. """

    return qutest_session
