How to solve AttributeError: 'Config' object has no attribute '_variables' for PyTest on Jenkins Execution

huangapple go评论74阅读模式
英文:

How to solve AttributeError: 'Config' object has no attribute '_variables' for PyTest on Jenkins Execution

问题

尝试使用Jenkins作业执行PyTest自动化脚本。最初,我配置了2个具有完全相同配置的Jenkins作业。脚本在这两个作业中都成功运行。后来,我创建了第3个具有完全相同配置的作业;但对于相同的脚本/配置,它抛出属性错误。请查看下面的错误详细信息,

"执行测试"
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\ProgramData\Jenkins\.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\_pytest\main.py", line 265, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "C:\ProgramData\Jenkins\.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\_pytest\config\__init__.py", line 1056, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "C:\ProgramData\Jenkins\.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy\_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "C:\ProgramData\Jenkins\.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\ProgramData\Jenkins\.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\ProgramData\Jenkins\.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\ProgramData\Jenkins\.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\ProgramData\Jenkins\.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pytest_selenium\pytest_selenium.py", line 249, in pytest_configure
INTERNALERROR>     capabilities = config._variables.get("capabilities", {})
INTERNALERROR> AttributeError: 'Config' object has no attribute '_variables'
"测试完成."

我正在使用的批处理命令是 -

pip install virtualenv
python -m virtualenv test
call .\test\Scripts\activate.bat
pip install -r requirements.txt
echo "执行测试"
python -m pytest ./src/scripts/activities -v -m mytags --environment="TestEnvironment" --stream="TestStream" --junitxml="test_results/results.xml"
call deactivate
echo "测试完成."

尝试以不同的配置执行脚本,例如更改批处理命令或不以系列方式运行这两个作业。

英文:

Trying to execute PyTest automation scripts using Jenkins Jobs. Initially I had configured 2 Jenkins Jobs with the exact same configuration. Scripts are running successfully with both jobs. Later I had created a 3rd job with the exact same configuration; but for same scripts/configuration it is throwing attribute error. Please find error details below,

<pre>
"Executing tests"
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "C:\ProgramData\Jenkins.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages_pytest\main.py", line 265, in wrap_session
INTERNALERROR> config.do_configure()
INTERNALERROR> File "C:\ProgramData\Jenkins.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages_pytest\config_init
.py", line 1056, in _do_configure
INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> File "C:\ProgramData\Jenkins.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy_hooks.py", line 277, in call_historic
INTERNALERROR> res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR> File "C:\ProgramData\Jenkins.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "C:\ProgramData\Jenkins.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "C:\ProgramData\Jenkins.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "C:\ProgramData\Jenkins.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pluggy_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "C:\ProgramData\Jenkins.jenkins\workspace\Integration-Automation\sf_venv\lib\site-packages\pytest_selenium\pytest_selenium.py", line 249, in pytest_configure
INTERNALERROR> capabilities = config._variables.get("capabilities", {})
INTERNALERROR> AttributeError: 'Config' object has no attribute '_variables'
"Test complete."
</pre>

Batch batch command I am using -

pip install virtualenv
python -m virtualenv test
call .\test\Scripts\activate.bat
pip install -r requirements.txt
echo &quot;Executing tests&quot;
python -m pytest ./src/scripts/activities -v -m mytags --environment=&quot;TestEnvironment&quot; --stream=&quot;TestStream&quot; --junitxml=&quot;test_results/results.xml&quot;
call deactivate
echo &quot;Test complete.&quot;

Tried to execute scripts with differenet configuration like changing batch commands or not running both jobs in series.

答案1

得分: 0

我遇到了相同的问题,虽然我还没有弄清楚到底是什么导致的,但我相当有信心这是升级到 pytest 7 的结果。相同的测试在 pytest 6.2.5 上正常工作,在 7.2.2 上失败。<br>
更新:实际上是 pytest-variables 3.0.0:
<li>在内部使用 pytest.stash 而不是 _variables </li><br>
https://github.com/pytest-dev/pytest-variables/blob/master/CHANGES.rst

英文:

I ran into the same problem, and while I haven't figured out what exactly is causing it, I'm pretty confident it is a result of upgrading to pytest 7. The same test works fine with pytest 6.2.5 and fails in 7.2.2. <br>
Update: It's actually pytest-variables 3.0.0:
<li>Use pytest.stash internally instead of _variables </li><br>
https://github.com/pytest-dev/pytest-variables/blob/master/CHANGES.rst

huangapple
  • 本文由 发表于 2023年6月19日 19:11:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76506068.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定