Skip to content

Commit

Permalink
Test examples update
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Oct 17, 2024
1 parent ef71851 commit d929237
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

class TestClass:
def test_fixture_class_setup(self, mocked_config):
class TestClassOne:
def test_fixture_class_setup_first(self, mocked_config):
assert mocked_config is not None

def test_fixture_class_setup_second(self, mocked_config):
assert mocked_config is not None


class TestClassTwo:
def test_fixture_class_setup_forth(self, mocked_config):
assert mocked_config is not None

def test_fixture_class_setup_fifth(self, mocked_config):
assert mocked_config is not None
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 EPAM Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

def test_fixture_package_setup_first(mocked_config):
assert mocked_config is not None
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

def test_fixture_package_setup_first(mocked_config):
assert mocked_config is not None


def test_fixture_package_setup_second(mocked_config):
assert mocked_config is not None
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 EPAM Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


def test_fixture_session_setup_first(mocked_config):
assert mocked_config is not None
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,5 @@
# limitations under the License.


def test_fixture_session_setup_first(mocked_config):
assert mocked_config is not None


def test_fixture_session_setup_second(mocked_config):
assert mocked_config is not None
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest import mock
import logging

import pytest
from reportportal_client import RPLogger

LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
logging.setLoggerClass(RPLogger)

LOG_MESSAGE_SETUP = 'Log message for setup and return None'


@pytest.fixture
def mocked_config():
yield mock.Mock()
print('teardown')
LOGGER.warn(LOG_MESSAGE_SETUP)
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from unittest import mock

import pytest
from reportportal_client import RPLogger

LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
logging.setLoggerClass(RPLogger)

LOG_MESSAGE_SETUP = 'Log message for setup'


@pytest.fixture
def mocked_config():
print('setup')
logging.error(LOG_MESSAGE_SETUP)
return mock.Mock()
29 changes: 29 additions & 0 deletions examples/fixtures/test_fixture_setup/test_fixture_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 EPAM Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


def test_fixture_setup(mocked_config):
assert mocked_config is not None
33 changes: 33 additions & 0 deletions examples/fixtures/test_fixture_teardown/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 EPAM Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from unittest import mock

import pytest
from reportportal_client import RPLogger

LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
logging.setLoggerClass(RPLogger)

LOG_MESSAGE_BEFORE_YIELD = 'Log message before yield'
LOG_MESSAGE_TEARDOWN = 'Log message for teardown'


@pytest.fixture
def mocked_config():
logging.error(LOG_MESSAGE_BEFORE_YIELD)
yield mock.Mock()
logging.error(LOG_MESSAGE_TEARDOWN)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from time import sleep


def test_fixture_teardown(mocked_config):
sleep(0.001)
assert mocked_config is not None

0 comments on commit d929237

Please sign in to comment.