当前位置: 首页 > news >正文

python 中 TypeError: self类型对象传入错误解决办法

错误收集

D:\Program\Util\python.exe "D:/Program/myUtil/PyCharm 2024.3.5/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py" --target test_login.py::TestLogin.test_got_register_page 
Testing started at 9:16 ...
Launching pytest with arguments test_login.py::TestLogin::test_got_register_page --no-header --no-summary -q in C:\Users\Administrator\PycharmProjects\PoPage

============================= test session starts =============================
collecting ... collected 1 item

test_login.py::TestLogin::test_got_register_page 

============================== 1 failed in 0.32s ==============================
FAILED                  [100%]
test_login.py:9 (TestLogin.test_got_register_page)
self = <test_login.TestLogin object at 0x0000024C8BB7E850>

    def test_got_register_page(self):
(index_info.IndexPage
>        .goto_login_page()
^^^^^^^^^^^^^^^^^
.login_to_register()
.register())
E       TypeError: IndexPage.goto_login_page() missing 1 required positional argument: 'self'

test_login.py:12: TypeError

Process finished with exit code 1

问题分析

这个问题应该是 对象没有实例化所导致的,看下面的图片,IndexPage类并没有实例化

看到前面的

解决方法

方法1

修改代码直接实例化

def test_got_register_page(self):(index_info.IndexPage().goto_login_page().login_to_register().register())

方法2

在当前类中添加一个属性,用于实例化IndexPage对象

运行结果

结果收集

D:\Program\Util\python.exe "D:/Program/myUtil/PyCharm 2024.3.5/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py" --target test_login.py::TestLogin.test_got_register_page 
Testing started at 9:44 ...
Launching pytest with arguments test_login.py::TestLogin::test_got_register_page --no-header --no-summary -q in C:\Users\Administrator\PycharmProjects\PoPage

============================= test session starts =============================
collecting ... collected 1 item

test_login.py::TestLogin::test_got_register_page 

============================= 1 passed in 11.62s ==============================
PASSED                  [100%]
Process finished with exit code 0

http://www.dtcms.com/a/306498.html

相关文章:

  • 在职申硕,怎么选适合自己的学科专业呢?
  • 计算机网络1-3:三种交换方式
  • sed编程入门
  • Android RTMP推送|轻量级RTSP服务同屏实践:屏幕+音频+录像全链路落地方案
  • 本地 docker 部署 HAR包分析工具 harviewer
  • 2025年7月技术问答第5期
  • MySQL: with as与with RECURSIVE如何混合使用?
  • 【算法】十大排序算法超深度解析,从数学原理到汇编级优化,涵盖 15个核心维度
  • 专题:2025机器人产业技术图谱与商业化指南|附130+份报告PDF、数据汇总下载
  • C++实战:抖音级视频应用开发精髓
  • LazyLLM教程 | 第2讲:10分钟上手一个最小可用RAG系统
  • [极客时间]LangChain 实战课 -----|(11) 记忆:通过Memory记住客户上次买花时的对话细节
  • macOS 设置 Claude Code
  • 02 NameServer是如何管理Broker集群的
  • 【STM32-HAL】 SPI通信与Flash数据写入实战
  • Elasticsearch(ES)基础语法(笔记)(持续更新)
  • MySQL索引和事务笔记
  • 如何通过项目管理系统提升交付率
  • Kafka 重复消费与 API 幂等消费解决方案
  • IO复用实现并发服务器
  • 【PZ7020-StarLite 入门级开发板】——FPGA 开发的理想起点,入门与工业场景的双重优选
  • 【工具】jsDelivr CDN完全指南:免费高速的开源项目CDN服务
  • Apache Ignite 与 Spring Boot 集成
  • Linux 进程管理与计划任务设置
  • 【Dv3admin】ORM数据库无法查询的问题
  • 如何修改VM虚拟机中的ip
  • opengauss数据库安装及测试
  • 【C语言】深度剖析指针(二):指针与数组,字符,函数的深度关联
  • SpringBoot中ResponseEntity的使用详解
  • .NET报表控件ActiveReports发布v19.0——正式兼容 .NET 9