From 111b1f7610e4fd7dfef718840a0639db2dbdd71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Hirsz?= Date: Wed, 3 Aug 2022 13:46:40 +0200 Subject: [PATCH] Migrate tox to nox (#673) * Migrate tox to nox * Update documentation fo tox->nox migration * Apply suggestions from code review Co-authored-by: Mateusz Nojek Co-authored-by: Mateusz Nojek --- CONTRIBUTING.rst | 31 +++++++++++++++------ noxfile.py | 49 +++++++++++++++++++++++++++++++++ setup.py | 1 - tox.ini | 71 ------------------------------------------------ 4 files changed, 71 insertions(+), 81 deletions(-) create mode 100644 noxfile.py delete mode 100644 tox.ini diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 1d56292bc..3de59d739 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -135,6 +135,11 @@ but most of it is located inside ``docs`` directory. The files are usually written using `reStructuredText format `_ (.rst). +To generate our documentation use ``nox`` tool that will create environment with required dependencies and generate +the documentation. Documentation will be available under ``docs/_build/index.html`` path:: + + nox -s docs + User manual ''''''''''' @@ -178,19 +183,23 @@ To run pytest tests navigate to directory with test files and run:: Pytest will automatically discover all the tests, run them and display results. Make sure that tests do not fail. -Together with Robocop installed with ``dev`` dependencies, you will be able to use -`tox `_ tool (a CI task automation tool) which can run all tests on different environments. -Currently two environments are available - one with Robot Framework v3.* and one with -Robot Framework v4.*. You can simply run:: +Nox +'''''''' +Robocop contains `nox `_ file for running the tests on all supported +major Robot Framework versions and generating the coverage or docs. The nox tool will create the virtual environment and +install required dependencies for you. + +Follow installation instruction from the ``nox`` documentation page. To execute Robocop tests run:: - tox + nox -and it will run all tests separately in these two environments and display the results. +Run the following command to see all possible sessions (acting as environments or targets):: -If you want to run tests for only one specific environment, you can choose between -``rf3`` and ``rf4`` and run them with option ``-e``, e.g.:: + nox --list - tox -e rf3 +You can select only one session per run. For example, to only run tests for ``Python==3.10`` and ``Robot Framework==3.*``:: + + nox --session "unit-3.10(robot_version='3')" Unit tests '''''''''' @@ -251,6 +260,10 @@ and then:: coverage html +You can also use ``nox`` tool:: + + nox -s coverage + HTML files will be generated - navigate to ``htmlcov`` directory and open ``index.html`` file. :: diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 000000000..de714e73e --- /dev/null +++ b/noxfile.py @@ -0,0 +1,49 @@ +import nox + +UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] +nox.options.sessions = [ + "unit", +] + + +def install_dev_deps(session, robot_major_ver): + session.install("-r", f"tests/packages/rf-stable{robot_major_ver}/requirements.txt") + session.install(".[dev]") + + +def install_doc_deps(session, robot_major_ver): + session.install("-r", f"tests/packages/rf-stable{robot_major_ver}/requirements.txt") + session.install(".[doc]") + + +@nox.session(python=UNIT_TEST_PYTHON_VERSIONS) +@nox.parametrize("robot_version", ["3", "4", "5"]) +def unit(session, robot_version): + install_dev_deps(session, robot_version) + session.run("pytest", "--benchmark-skip", "tests") + + +@nox.session() +def coverage(session): + install_dev_deps(session, "5") + session.install("coverage") + session.run("coverage", "run", "-m", "pytest") + session.run("coverage", "html") + + +@nox.session() +def docs(session): + install_doc_deps(session, "5") + session.run("sphinx-build", "-b", "html", "docs", "docs/_build/") + + +@nox.session() +def benchmark(session): + install_dev_deps(session, "5") + session.run( + "pytest", + "--benchmark-only", + "--benchmark-enable", + "--benchmark-save=benchmark_results", + "--benchmark-save-data", + ) diff --git a/setup.py b/setup.py index 322a612e4..cc663d74b 100644 --- a/setup.py +++ b/setup.py @@ -67,7 +67,6 @@ "pytest", "pytest-benchmark", "pyyaml", - "tox", ], "doc": [ "furo", diff --git a/tox.ini b/tox.ini deleted file mode 100644 index a5b77c52f..000000000 --- a/tox.ini +++ /dev/null @@ -1,71 +0,0 @@ -[tox] -envlist = rf3, rf4, rf5 -skip_missing_interpreters = true -[pytest] -addopts = --benchmark-skip --lf -[testenv] -commands = pytest tests -[testenv:rf3] -deps = - jinja2>=3.0,<4.0 - pathspec - pytest - pytest-benchmark - pyyaml - robotframework==3.2.2 - toml -[testenv:rf4] -deps = - jinja2>=3.0,<4.0 - pathspec - pytest - pytest-benchmark - pyyaml - robotframework==4.1.1 - toml -[testenv:rf5] -deps = - jinja2>=3.0,<4.0 - pathspec - pytest - pytest-benchmark - pyyaml - robotframework==5.0rc2 - toml -[testenv:coverage] -deps = - coverage - jinja2>=3.0,<4.0 - pytest - pytest-benchmark - pyyaml - robotframework - toml -commands = - coverage run -m pytest - coverage html -[testenv:docs] -deps = - furo - jinja2>=3.0,<4.0 - packaging>=21.0,<22.0 - pathspec>=0.9,<0.10 - robotframework>=4.0 - sphinx - sphinx_design - toml>=0.10.2 -commands = - sphinx-build -b html docs docs/_build/ -[testenv:benchmark] -deps = - pygal - pytest - pytest-benchmark - pyyaml - robotframework==4.1.1 - toml -commands = - pytest --benchmark-only \ - --benchmark-enable \ - --benchmark-save=benchmark_results \ - --benchmark-save-data