Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
output.xml
log.html
report.html
robot2python_output
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "robot2python",
"type": "python",
"request": "launch",
"program": "pytest_robotframework/robot2python.py",
"args": ["${input:robot2pythonInput}", "robot2python_output"],
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "pytest justMyCode disabled",
"type": "python",
Expand All @@ -19,6 +28,12 @@
"type": "promptString",
"description": "args for pytest",
"default": ""
},
{
"id": "robot2pythonInput",
"type": "promptString",
"description": "robot test suite to convert to python",
"default": ""
}
]
}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ def test_bar():
...
```

## automatically convert `.robot` tests to `.py`

pytest-robotframework comes with a script to automatically convert tests from robot to python:

```
robot2python ./foo.robot ./tests
```

this will convert the `foo.robot` file to an equivalent `test_foo.py` file and output it to the `tests` directory.

### limitations

note that the script is not perfect and you will probably have to make manual changes to tests converted with it.

- robot converters are not yet used, so all arguments to keywords are assumed to be strings in the converted python code.
- some of the control flows possible in robot aren't able to be accurately converted to python (see [here](#continuable-failures-dont-work)). the script attempts to convert what it can but you will probably have to rewrite parts of your tests that use continuable failures

## setup/teardown and other hooks

to define a function that runs for each test at setup or teardown, create a `conftest.py` with a `pytest_runtest_setup` and/or `pytest_runtest_teardown` function:
Expand Down
16 changes: 15 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ dependencies = [
"robotframework<7.0.0,>=6.1.1",
"deepmerge<2.0.0,>=1.1.0",
"basedtyping<0.2,>=0.1.0",
"typer>=0.9.0",
"astunparse>=1.6.3",
]
requires-python = ">=3.8,<4.0"
readme = "README.md"
Expand All @@ -21,6 +23,9 @@ repository = "https://github.com/detachhead/pytest-robotframework"
[project.entry-points.pytest11]
robotframework = "pytest_robotframework._internal.plugin"

[project.scripts]
robot2python = "pytest_robotframework._internal.scripts.robot2python:main"

[tool.pyprojectx]
pdm = "pdm==2.10.4"

Expand Down Expand Up @@ -221,7 +226,6 @@ enable = [
"unnecessary-ellipsis",
"unreachable",
"unused-private-member",
"unused-wildcard-import",
"useless-param-doc",
"useless-parent-delegation",
"useless-type-doc",
Expand Down Expand Up @@ -274,23 +278,24 @@ xfail_strict = true
enable_assertion_pass_hook = true

[tool.mypy]
allow_redefinition = true
allow_redefinition = false
default_return = false
cache_dir = 'nul' # disable cache because it sucks
cache_dir = 'nul' # disable cache because it sucks

[[tool.mypy.overrides]]
module = ['robot.*']
no_implicit_reexport = false
ignore_missing_py_typed = true # https://github.com/robotframework/robotframework/issues/4822

[[tool.mypy.overrides]]
module = ['deepmerge.*']
module = ['deepmerge.*', 'astunparse.*']
ignore_missing_py_typed = true

[[tool.mypy.overrides]]
module = ['pytest_robotframework.*', 'tests.*']
default_return = true


[tool.pyright]
pythonVersion = "3.8"
pythonPlatform = "All"
Expand Down Expand Up @@ -380,6 +385,10 @@ fixture-parentheses = false
"tests/**/*.py" = [
"S101", # Use of assert detected (pytest uses assert statements)
]
"tests/fixtures/test_robot2python/**/*.py" = [
"INP001", # implicit-namespace-package
]

[tool.ruff.isort]
combine-as-imports = true
required-imports = ["from __future__ import annotations"]
Expand Down
Empty file.
Loading