def pytest_collect_file(parent, path): if (path.ext == ".hy" and path.basename != "__init__.hy" and "#" not in path.basename and "test" in path.basename): pytest_mod = pytest.Module(path, parent) return pytest_mod
def collect(self): # First, just do the regular import of the module to make # sure it's sane and valid. This block is copied directly # from py.test try: mod = self.fspath.pyimport(ensuresyspath=True) except SyntaxError: import py excinfo = py.code.ExceptionInfo() raise self.CollectError(excinfo.getrepr(style="short")) except self.fspath.ImportMismatchError: e = sys.exc_info()[1] raise self.CollectError( "import file mismatch:\n" "imported module {!r} has this __file__ attribute:\n" " {}\n" "which is not the same as the test file we want to collect:\n" " {}\n" "HINT: remove __pycache__ / .pyc files and/or use a " "unique basename for your test file modules".format(e.args)) # Now get the file's content. with io.open(six.text_type(self.fspath), 'rb') as fd: content = fd.read() # If the file contains the special marker, only test it both ways. if b'TEST_UNICODE_LITERALS' in content: # Return the file in both unicode_literal-enabled and disabled forms return [ UnicodeLiteralsModule(mod.__name__, content, self.fspath, self), NoUnicodeLiteralsModule(mod.__name__, content, self.fspath, self) ] else: return [pytest.Module(self.fspath, self)]
def pytest_collect_file(parent, path): if path.ext == ".hy" and path.basename != "__init__.hy": if hasattr(pytest.Module, "from_parent"): pytest_mod = pytest.Module.from_parent(parent, fspath=path) else: pytest_mod = pytest.Module(path, parent) return pytest_mod
def pytest_collect_file(parent, path): if (path.ext == ".hy" and NATIVE_TESTS in path.dirname + os.sep and path.basename != "__init__.hy" and not ("py3_only" in path.basename and not PY3) and not ("py35_only" in path.basename and not PY35) and not ("py36_only" in path.basename and not PY36)): return pytest.Module(path, parent)
def collect(self): test_cases = yaml.load(self.fspath.open()) for case in test_cases: module = py.path.local(str(self.fspath).replace(".yml", ".py")) yield pytest.Function( name=case['mapset'], # parent=pytest.Module(fspath=os.path.abspath(__file__), parent=self), parent=pytest.Module(fspath=module, parent=self), callobj=functools.partial(estimap_test_runner, case))
def pytest_collect_file(parent, path): if (path.ext == ".hy" and NATIVE_TESTS in path.dirname + os.sep and path.basename != "__init__.hy"): if hasattr(pytest.Module, "from_parent"): pytest_mod = pytest.Module.from_parent(parent, fspath=path) else: pytest_mod = pytest.Module(path, parent) return pytest_mod
def pytest_pycollect_makemodule(path, parent): # This is where we set up testing both with and without # from __future__ import unicode_literals # On Python 3, just do the regular thing that py.test does if six.PY2: return Pair(path, parent) else: return pytest.Module(path, parent)
def pytest_pycollect_makemodule(path, parent): entrypoint = find_launch_test_entrypoint(path) if entrypoint is not None: ihook = parent.session.gethookproxy(path) module = ihook.pytest_launch_collect_makemodule(path=path, parent=parent, entrypoint=entrypoint) if module is not None: return module if path.basename == '__init__.py': return pytest.Package(path, parent) return pytest.Module(path, parent)
def pytest_pycollect_makemodule(path, parent): """Dynamically creates mock fixtures for the current module. Provide a list of module/function paths in the `pytest_mock_fixtures` attribute of the test module: pytest_mock_fixtures = [ 'module.function_name', ] This becomes equivalent to: @pytest.fixture def function_name(mocker): return mocker.patch('module.function_name') So you can use the mock in a test fixture like this: def test_something(function_name): function_name.return_value = [1, 2, 3] call_something() function_name.assert_called_with(...) Requires pytest-mock. """ module = path.pyimport() try: mocks = module.pytest_mock_fixtures except AttributeError: return for m in mocks: _, name = m.rsplit('.', 1) def _make_fixture(function_path, name): @pytest.fixture(scope='function') def dummy(mocker): return mocker.patch(function_path) dummy.__name__ = name return dummy if getattr(module, name, None) is not None: raise AttributeError('Mock fixture name aliases existing module ' 'attribute "%s" in module "%s".' % (name, module.__name__)) setattr(module, name, _make_fixture(m, name)) return pytest.Module(path, parent)
def collect(self): # First, just do the regular import of the module to make # sure it's sane and valid. This block is copied directly # from py.test try: mod = self.fspath.pyimport(ensuresyspath=True) except SyntaxError: import py excinfo = py.code.ExceptionInfo() raise self.CollectError(excinfo.getrepr(style="short")) except self.fspath.ImportMismatchError: e = sys.exc_info()[1] raise self.CollectError( "import file mismatch:\n" "imported module {!r} has this __file__ attribute:\n" " {}\n" "which is not the same as the test file we want to collect:\n" " {}\n" "HINT: remove __pycache__ / .pyc files and/or use a " "unique basename for your test file modules".format(e.args)) return [pytest.Module(self.fspath, self)]
def pytest_pycollect_makemodule(path, parent): entrypoint = find_launch_test_entrypoint(path) if entrypoint is not None: ihook = parent.session.gethookproxy(path) module = ihook.pytest_launch_collect_makemodule(path=path, parent=parent, entrypoint=entrypoint) if module is not None: return module if path.basename == '__init__.py': try: # since https://docs.pytest.org/en/latest/changelog.html#deprecations # todo: remove fallback once all platforms use pytest >=5.4 return pytest.Package.from_parent(parent, fspath=path) except AttributeError: return pytest.Package(path, parent) try: # since https://docs.pytest.org/en/latest/changelog.html#deprecations # todo: remove fallback once all platforms use pytest >=5.4 return pytest.Module.from_parent(parent, fspath=path) except AttributeError: return pytest.Module(path, parent)
def pytest_pycollect_makemodule(path, parent): """ py.test hook called when a new test module is generated. If your test module contains a class named "Fixtures" with :class:`Fixture` instances as (class) attributes, this will set up "lazy" fixtures to use within the test module. """ mod = path.pyimport() fixtures = getattr(mod, 'Fixtures', None) if not fixtures is None: fixtures = [ item for item in fixtures.__dict__.items() if (callable(item[1]) and not item[0].startswith('_')) ] for (fx_name, func) in fixtures: if getfixturemarker(func) is None: fxt = pytest.fixture(scope='function')(func) else: fxt = func setattr(mod, fx_name, fxt) return pytest.Module(path, parent)
def pytest_pycollect_makemodule(path, parent): # This is where we set up testing both with and without return pytest.Module(path, parent)
def pytest_collect_file(path, parent): if path.ext == ".hy": return pytest.Module(path, parent)
def pytest_collect_file(parent, path): if path.ext.startswith(".py") and (path.basename.startswith("test_") or path.basename.startswith("catch_")): return pytest.Module(path, parent)
def pytest_collect_file(parent, path): if (path.ext == ".hy" and NATIVE_TESTS in path.dirname + os.sep and path.basename != "__init__.hy"): pytest_mod = pytest.Module(path, parent) return pytest_mod
def pytest_collect_file(parent, path): if path.ext == ".hy" and path.basename != "__init__.hy": pytest_mod = pytest.Module(path, parent) return pytest_mod