Skip to content

[setup.py] Added an option for providing additional arguments to pytest #1643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 32 commits into from

Conversation

vivekrnv
Copy link
Contributor

Signed-off-by: Vivek Reddy Karri [email protected]

Currently, the only option to run unit tests is to use this command, pytest setup.py test. This executes all the unit tests even though user only wants to run a few and also no control over pytest arguments

What I did

Added an argument '-a' to the python3 setup.py test command which takes in pytest related arguments.

Essentially, python3 setup.py test -a "<args>" translates to pytest <args>

How I did it

Pulled the code from the pytest-setuptools integration documentation which is deprecated now
Link

Rationale for change made in scripts/route_check.py:

Although this was meant to be used as a script, the main method in this module is invoked by the tests/route_check_test.py and hence the arguments passed to route_check_test are inturn passed to the route_check() script and hence an error is thrown when parse_arguments() is used.
Therefore parse_arguments is replaced with parse_known_arguments()

How to verify it

python3 setup.py test -a "-k 'Test_Aaa'" # To only run the tests under Test_Aaa class

============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.7.3, pytest-3.10.1, py-1.7.0, pluggy-0.8.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /sonic/src/sonic-utilities, inifile: pytest.ini
plugins: pyfakefs-4.4.0, cov-2.6.0
collected 1009 items / 1005 deselected

tests/aaa_test.py::TestAaa::test_show_aaa_default PASSED                                                                                                                                               [ 25%]
tests/aaa_test.py::TestAaa::test_config_aaa_radius PASSED                                                                                                                                              [ 50%]
tests/aaa_test.py::TestAaa::test_config_aaa_radius_local PASSED                                                                                                                                        [ 75%]
tests/aaa_test.py::TestAaa::test_config_aaa_radius_invalid PASSED                                                                                                                                      [100%]

Others:
python3 setup.py test -a "-x'" # To stop at the first failure
python3 setup.py test -a "-x -k 'Test_Aaa'" # Multiple arguments can be given as well

This did not break any functionality

vkarri@r-build-sonic06:/builds2/vkarri/sonic/sonic-buildimage$ make NOJESSIE=1 NOSTRETCH=1 target/python-wheels/sonic_utilities-1.2-py3-none-any.whl
.. (Exisiting Tests did pass and package build was successful as well)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
================== 1029 passed, 1 warnings in 174.55 seconds ===================

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

vivekrnv and others added 27 commits May 6, 2021 05:32
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
Signed-off-by: Vivek Reddy Karri <[email protected]>
@liat-grozovik liat-grozovik requested a review from jleveque June 16, 2021 16:42
@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lguohan
Copy link
Contributor

lguohan commented Jul 13, 2021

to run pytest, can we invoke pytest directly instead of python3 setup.py test? it seems your requirement is just to run pytest for a particular test. I am not sure using python3 setup.py test is the right way to do it.

@vivekrnv vivekrnv closed this Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants