File: module_getter.py

package info (click to toggle)
python-pytest-resource-path 1.3.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192 kB
  • sloc: python: 398; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 925 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Implements getting process for module object in pytest by pytest file name and testdir object."""
import sys

if sys.version_info.major == 3 and sys.version_info.minor <= 5:  # pragma: nocover
    import pathlib2  # type: ignore # pylint: disable=import-error
else:  # pragma: nocover
    import pathlib


class ModuleGetter:
    """Implements getting process for nodule object in pytest by pytest file name and testdir object."""

    @staticmethod
    def get(file_name_pytest: str, testdir_structure):
        """Gets module object."""
        path_to_python_file_string = "tests/test_package/" + file_name_pytest + ".py"
        if sys.version_info.major == 3 and sys.version_info.minor <= 5:  # pragma: nocover
            path = pathlib2.Path(path_to_python_file_string)
        else:  # pragma: nocover
            path = pathlib.Path(path_to_python_file_string)
        return testdir_structure.getmodulecol(path)