Python 如何从模块中测试函数的代码执行pytest

Python 如何从模块中测试函数的代码执行pytest,python,testing,pytest,databricks,Python,Testing,Pytest,Databricks,我在一个托管笔记本环境(Databricks)中工作。我能访问的只是笔记本本身,我想在那里执行集成测试 是否可以让pytest在当前作用域中选择test\u函数,而不是扫描文件 我在找这样的东西: import pytest @pytest.fixture(scope='session') def session_fixture(): return "" def test_this_1(session_fixture): assert False def

我在一个托管笔记本环境(Databricks)中工作。我能访问的只是笔记本本身,我想在那里执行集成测试

是否可以让pytest在当前作用域中选择
test\u
函数,而不是扫描文件

我在找这样的东西:

import pytest


@pytest.fixture(scope='session')
def session_fixture():
  return ""

def test_this_1(session_fixture):
  assert False
  
def test_this_2(session_fixture):
  assert True
  
pytest.<<pytest command to pytest `test_this_1` and `test_this_2`>>
导入pytest
@pytest.fixture(scope='session')
def会话_fixture():
返回“”
def测试\u此\u 1(会话\u夹具):
断言错误
def测试\u此\u 2(会话\u夹具):
断言正确
皮特斯特。

pytest.main
执行与命令行调用相同的操作,命令行参数作为列表传递,因此如果要将测试限制到特定文件,可以将文件名作为参数传递。