Pytest+PyInstaller 生成并启动exe文件

        相比其他教程,这篇的重点是pytest这边的设置而不是PyInstaller的,相比PyInstaller 的步骤应该会更简单一些,但是这次的项目并不是很复杂,只是单纯的一个实验仅供参考。

文件结构:

        用框画出的部分是执行完第二步才会出现的,单文件会执行这个文件夹下的其中一个文件,多文件会执行这个文件夹下面的所有文件。 

 

1.在pytest项目中配置app.main文件

        a.参考官方文档下的Freezing pytest

        If you freeze your application using a tool like PyInstaller in order to distribute it to your end-users, it is a good idea to also package your test runner and run your tests using the frozen application. This way packaging errors such as dependencies not being included into the executable can be detected early while also allowing you to send test files to users so they can run them in their machines, which can be useful to obtain more information about a hard to reproduce bug.

        如果你想要使用像PyInstaller这样的工具去冻结你的应用程序将它分发给你的客户,将你运行的测试进行打包并且使用冻结程序去运行将会是一个很好的方法。这个方法将会打包错误,例如依赖没有被包括在可执行文件中这个错误将会被提早侦察出来,它同时也

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用 Appium、Pytest 和 Allure 来生成测试淘宝 App 的完整框架时,可以按照以下步骤进行: 1. 安装必要的软件和库: - 安装 Python:访问 Python 官方网站(https://www.python.org/),下载并安装最新版本的 Python。 - 安装 Pytest:在命令行中运行 `pip install pytest`。 - 安装 Appium-Python-Client:在命令行中运行 `pip install Appium-Python-Client`。 - 安装 Allure-Pytest:在命令行中运行 `pip install allure-pytest`。 2. 配置 Appium 环境: - 下载并安装 Appium Desktop(https://github.com/appium/appium-desktop)。 - 启动 Appium Desktop,并设置 Appium 服务器的相关配置,如设备连接信息、应用程序路径等。 3. 创建测试文件和目录结构: - 创建一个新的目录来保存你的测试代码和相关文件。 - 在该目录下创建一个名为 `conftest.py` 的文件,用于配置测试环境和共享的方法。 - 创建一个名为 `test_taobao.py` 的文件,用于编写测试用例和测试步骤。 4. 编写测试用例: - 在 `test_taobao.py` 文件中导入所需的库和模块,如 `pytest`、`Appium-Python-Client`、`allure` 等。 - 编写测试用例,可以使用 `pytest` 提供的装饰器来标记测试用例,如 `@pytest.mark.parametrize`、`@pytest.fixture` 等。 - 在测试用例中,使用 `Appium-Python-Client` 提供的方法来控制 Appium 服务器和执行 App 操作,如启动 App、查找元素、点击按钮等。 - 可以使用 `allure` 提供的装饰器和方法来添加测试步骤、生成测试报告、添加截图等。 5. 运行测试用例: - 在命令行中进入到测试代码所在的目录。 - 运行命令 `pytest --alluredir=./allure-results` 来执行测试用例,并生成 Allure 报告所需的数据。 6. 生成测试报告: - 在命令行中运行 `allure serve ./allure-results` 来生成并打开 Allure 报告。 以下是一个简单的示例代码,用于演示如何使用 Appium、Pytest 和 Allure 进行淘宝 App 的自动化测试: ```python import allure import pytest from appium import webdriver @pytest.fixture(scope='session') def driver(): desired_caps = { 'platformName': 'Android', 'deviceName': 'YourDeviceName', 'appPackage': 'com.taobao.taobao', 'appActivity': 'com.taobao.tao.homepage.MainActivity3', 'noReset': True } driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) yield driver driver.quit() @allure.feature('淘宝 App 测试') class TestTaobaoApp: @allure.story('搜索商品') def test_search_product(self, driver): with allure.step('启动淘宝 App'): # 启动淘宝 App with allure.step('搜索商品'): # 在搜索框中输入关键词 with allure.step('点击搜索按钮'): # 点击搜索按钮 with allure.step('验证搜索结果'): # 验证搜索结果是否符合预期 with allure.step('添加截图'): # 添加当前页面的截图到报告中 allure.attach(driver.get_screenshot_as_png(), name='搜索结果截图', attachment_type=allure.attachment_type.PNG) ``` 请根据你的具体测试需求和环境配置,修改和扩展上述示例代码。这只是一个简单的框架示例,具体的实现方式可能因项目要求和测试需求而有所不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值