How use pipe character inside Examples table of Behave test .feature file?

只谈情不闲聊 提交于 2020-06-16 02:21:17

问题


I have a Behave Scenario outline where I need to use pipe character - | as a cell value inside Examples table. But I don't know how to escape this character to not be treated as column separator. I'm getting Malformed table error when I try to use \| sequence.


回答1:


As far as I can tell, it is not possible to escape cell delimiters as of version 1.2.5 (current at the time of posting). The relevant code is in the action_table method. This is how it splits a line into cells:

cells = [cell.strip() for cell in line.split('|')[1:-1]]

I searched before and after this line but did not see code that would transform sequences like \| or anything similar into something that .split('|') would not affect.

The only solution I see, as of 1.2.5, would be to hand-code the content of your cells so that you use another character than | in the cell data and then convert it to | in your Python code. For instance, using !, you could have in the feature file:

| foo!bar |

and then convert ! to | in your step implementations. This is awful but I don't see another way to get what you want.



来源:https://stackoverflow.com/questions/34357982/how-use-pipe-character-inside-examples-table-of-behave-test-feature-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!