Skip to content
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

Running 1 test with --no-discover results in an error #244

Closed
relaxdiego opened this issue Jun 12, 2019 · 5 comments · Fixed by #255 or #256
Closed

Running 1 test with --no-discover results in an error #244

relaxdiego opened this issue Jun 12, 2019 · 5 comments · Fixed by #255 or #256
Assignees
Labels

Comments

@relaxdiego
Copy link

Issue description

When attempting to run a single test method in test file, as specified in the documentation, stestr errors out with the following:

Traceback (most recent call last):
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/bin/stestr", line 10, in <module>
    sys.exit(main())
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/cli.py", line 111, in main
    return cli.run(argv)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/cliff/app.py", line 281, in run
    result = self.run_subcommand(remainder)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/cliff/app.py", line 401, in run_subcommand
    result = cmd.run(parsed_args)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/cliff/command.py", line 184, in run
    return_code = self.take_action(parsed_args) or 0
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/run.py", line 213, in take_action
    suppress_attachments=suppress_attachments)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/run.py", line 366, in run_command
    return run_tests()
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/run.py", line 363, in run_tests
    suppress_attachments=suppress_attachments)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/load.py", line 209, in load
    color, stdout, abbreviate, suppress_attachments)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/load.py", line 251, in _load_case
    start_time = min(start_times)
ValueError: min() arg is an empty sequence
ERROR: InvocationError: '/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/bin/stestr run --no-discover unit_tests/test_lib_charm_openstack_cinder_freenas.py::TestCinderFreeNASCharm::test_cinder_base'

Expected behavior and actual behavior

It executes successfully with the following output:

{0} unit_tests.test_lib_charm_openstack_cinder_freenas.TestCinderFreeNASCharm.test_cinder_base [0.001872s] ... ok

======
Totals
======
Ran: 1 tests in 0.0019 sec.
 - Passed: 1
 - Skipped: 0
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 0
Sum of execute time for each test: 0.0019 sec.

==============
Worker Balance
==============
 - Worker 0 (1 tests) => 0:00:00.001872
___________________________________________________________________________________________________________________________________ summary ____________________________________________________________________________________________________________________________________
  py3: commands succeeded
  congratulations :)

Steps to reproduce the problem

Run a single test as per documentation:

stestr run --no-discover project/tests/test_foo.py::TestFoo::test_method

Reference: https://stestr.readthedocs.io/en/latest/MANUAL.html#running-tests

Specifications like the version of the project, operating system, or hardware

multipass@dev:~/src/review.opendev.org/cinder-freenas$ uname -a
Linux dev 4.15.0-51-generic #55-Ubuntu SMP Wed May 15 14:27:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

System information

stestr version (stestr --version): 2.3.1

Python release (python --version): Python 3.6

pip packages (pip freeze): attrs==19.1.0,charmhelpers==0.19.13,charms.openstack==0.0.1.dev1,charms.reactive==1.2.1,cliff==2.14.1,cmd2==0.9.12,colorama==0.4.1,coverage==4.5.3,entrypoints==0.3,extras==1.0.0,fixtures==3.0.0,flake8==3.7.7,future==0.17.1,Jinja2==2.10.1,linecache2==1.0.0,MarkupSafe==1.1.1,mccabe==0.6.1,mock==3.0.5,netaddr==0.7.19,os-testr==1.0.0,pbr==5.2.1,pkg-resources==0.0.0,prettytable==0.7.2,pyaml==19.4.1,pycodestyle==2.5.0,pyflakes==2.1.1,pyparsing==2.4.0,pyperclip==1.7.0,python-mimeparse==1.6.0,python-subunit==1.3.0,PyYAML==5.1.1,six==1.12.0,stestr==2.3.1,stevedore==1.30.1,Tempita==0.5.2,testtools==2.3.0,traceback2==1.4.0,unittest2==1.1.0,voluptuous==0.11.5,wcwidth==0.1.7

Additional information

Running an alternative command as a workaround:

stestr run unit_tests.test_lib_charm_openstack_cinder_freenas.TestCinderFreeNASCharm.test_cinder_base
{0} unit_tests.test_lib_charm_openstack_cinder_freenas.TestCinderFreeNASCharm.test_cinder_base [0.002587s] ... ok

======
Totals
======
Ran: 1 tests in 0.0026 sec.
 - Passed: 1
 - Skipped: 0
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 0
Sum of execute time for each test: 0.0026 sec.

==============
Worker Balance
==============
 - Worker 0 (1 tests) => 0:00:00.002587
___________________________________________________________________________________________________________________________________ summary ____________________________________________________________________________________________________________________________________
  py3: commands succeeded
  congratulations :)

However, the above is slow since stestr first needs to discover all tests before it filters it down to the one I wanted to run.

@mtreinish
Copy link
Owner

Thanks for filing this, I can confirm this is an issue, I actually hit it yesterday for the first time myself locally and was going to spend some time investigating it today.

@mtreinish mtreinish added the bug label Jun 12, 2019
@mtreinish mtreinish self-assigned this Jun 12, 2019
@mtreinish
Copy link
Owner

@relaxdiego So I've been doing some local debugging on my issues. There are 2 things going on, first the ValueError: min() arg is an empty sequence is being caused because there are no results in the output from the test execution, I have a patch to fix that (it's relatively straightforward and I'll push it up shortly).

But it doesn't fix the underlying fault causing the lack of results. In my case in the local test suite where I was hitting this issue it was caused by a bug in testtools (well really unittest2) when running that test suite without discovery. It did raise an error from the subunit worker process when it tried to run the test specified and that's why there weren't any results. I'm thinking there might be an underlying error happening early in the test execution that's causing this for you too. Is the test suite you're running this on open so I can take a look? If not can you see if there are any other errors above the traceback you pasted here already?

@relaxdiego
Copy link
Author

@mtreinish Thanks for the quick feedback! Below is the entire stacktrace. HTH!

stestr run --no-discover unit_tests.test_lib_charm_openstack_cinder_freenas::TestCinderFreeNASCharm::test_cinder_base                            [27/501]
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/subunit/run.py", line 149, in <module>
    main()
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/subunit/run.py", line 145, in main
    stdout=stdout, exit=False)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/testtools/run.py", line 171, in __init__
    self.parseArgs(argv)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/unittest2/main.py", line 135, in parseArgs
    self.createTests()
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/unittest2/main.py", line 142, in createTests
    self.module)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/unittest2/loader.py", line 245, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/unittest2/loader.py", line 245, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/unittest2/loader.py", line 230, in loadTestsFromName
    test = obj()
TypeError: test_cinder_base() missing 1 required positional argument: 'self'
min() arg is an empty sequence                                                                                                                                                       Traceback (most recent call last):
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/cliff/app.py", line 401, in run_subcommand                                            result = cmd.run(parsed_args)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/cliff/command.py", line 184, in run
    return_code = self.take_action(parsed_args) or 0
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/run.py", line 213, in take_action
    suppress_attachments=suppress_attachments)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/run.py", line 366, in run_command
    return run_tests()
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/run.py", line 363, in run_tests
    suppress_attachments=suppress_attachments)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/load.py", line 209, in load
    color, stdout, abbreviate, suppress_attachments)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/load.py", line 251, in _load_case
    start_time = min(start_times)
ValueError: min() arg is an empty sequence
Traceback (most recent call last):
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/bin/stestr", line 10, in <module>
    sys.exit(main())
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/cli.py", line 111, in main
    return cli.run(argv)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/cliff/app.py", line 281, in run
    result = self.run_subcommand(remainder)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/cliff/app.py", line 401, in run_subcommand
    result = cmd.run(parsed_args)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/cliff/command.py", line 184, in run
    return_code = self.take_action(parsed_args) or 0                                                                                                                                   File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/run.py", line 213, in take_action
    suppress_attachments=suppress_attachments)                                                                                                                                         File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/run.py", line 366, in run_command
    return run_tests()
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/run.py", line 363, in run_tests
    suppress_attachments=suppress_attachments)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/load.py", line 209, in load
    color, stdout, abbreviate, suppress_attachments)
  File "/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/lib/python3.6/site-packages/stestr/commands/load.py", line 251, in _load_case
    start_time = min(start_times)
ValueError: min() arg is an empty sequence
ERROR: InvocationError: '/home/multipass/src/review.opendev.org/cinder-freenas/.tox/py3/bin/stestr run --no-discover unit_tests.test_lib_charm_openstack_cinder_freenas::TestCinderFr
eeNASCharm::test_cinder_base'

mtreinish added a commit that referenced this issue Jul 18, 2019

Verified

This commit was signed with the committer’s verified signature. The key has expired.
litvinovg Georgy Litvinov
This commit fixes an edge case with the load command when there are no
test events in the subunit stream being passed to load. If the
pretty_out flag is set for the load command and there is no subunit
output the processing being used to handle the test run timing will fail
because there are no tests. This fixes that by just returning the test
run failed (because there were no sucessful tests run).

Fixes #244
@mtreinish
Copy link
Owner

I just pushed #255 which will fix the stestr issue reported here (which is the ValueError: min() stacktrace). The first stacktrace is actually the same thing I was hitting and is caused by bug in unittest2 when using a test class based off of unittest (instead of testtools or unittest2). I pushed up testing-cabal/testtools#277 to address it, but that will probably be a while until it merges (if it does at all).

mtreinish added a commit that referenced this issue Jul 21, 2019
Right now stestr doesn't actually own it's own test runner. It leverages
the subunit.run test runner, subunit.run in turn inherets from
testtools.run, which inherets from unittest2. The usage of unittest2
causes all sorts of problems when running non-testtools or non-unittest2
test suites, because of mismatches between stdlib unittest and unittest2.
To address this proble this commit creates a new test runner for stestr
that will emit subunit which is the actual only hard requirement for the
internal test runner used. This new test runner is more or less identical
to subunit.run, but instead of inheriting from testtools it uses stdlib
unittest directly.

Python 2.7's stdlib unittest's test runner is much older and it was
changed significantly for python 3. So building a custom test runner
based on python 2's unittest would basically requiring maintaining a
completely separate copy of python 3's unittest runner in tree and then
building the subunit runner off of that, which is essentially what
unittest2 is anyway. Since python 2 support is deprecated anyway and
will be going away soon this commit just maintains the current status
quo of basing it off testtools for python 2.

Fixes #244 for the first stacktrace outlined there, which was caused by
the test runner (which was previously outside the scope of stestr).
mtreinish added a commit that referenced this issue Jul 21, 2019
Right now stestr doesn't actually own it's own test runner. It leverages
the subunit.run test runner, subunit.run in turn inherets from
testtools.run, which inherets from unittest2. The usage of unittest2
causes all sorts of problems when running non-testtools or non-unittest2
test suites, because of mismatches between stdlib unittest and unittest2.
To address this problem this commit creates a new test runner for stestr
that will emit subunit which is the actual only hard requirement for the
internal test runner used. This new test runner is more or less identical
to subunit.run, but instead of inheriting from testtools it uses stdlib
unittest directly.

Python 2.7's stdlib unittest's test runner is much older and it was
changed significantly for python 3. So building a custom test runner
based on python 2's unittest would basically requiring maintaining a
completely separate copy of python 3's unittest runner in tree and then
building the subunit runner off of that, which is essentially what
unittest2 is anyway. Since python 2 support is deprecated anyway and
will be going away soon this commit just maintains the current status
quo of basing it off testtools for python 2.

Most of the code here for the Runner class and the TestProgram class
were originally taken from subunit and testtools respectively.

Fixes #244 for the first stacktrace outlined there, which was caused by
the test runner (which was previously outside the scope of stestr).
mtreinish added a commit that referenced this issue Jul 21, 2019
Right now stestr doesn't actually own it's own test runner. It leverages
the subunit.run test runner, subunit.run in turn inherets from
testtools.run, which inherets from unittest2. The usage of unittest2
causes all sorts of problems when running non-testtools or non-unittest2
test suites, because of mismatches between stdlib unittest and unittest2.
To address this problem this commit creates a new test runner for stestr
that will emit subunit which is the actual only hard requirement for the
internal test runner used. This new test runner is more or less identical
to subunit.run, but instead of inheriting from testtools it uses stdlib
unittest directly.

Python 2.7's stdlib unittest's test runner is much older and it was
changed significantly for python 3. So building a custom test runner
based on python 2's unittest would basically requiring maintaining a
completely separate copy of python 3's unittest runner in tree and then
building the subunit runner off of that, which is essentially what
unittest2 is anyway. Since python 2 support is deprecated anyway and
will be going away soon this commit just maintains the current status
quo of basing it off testtools for python 2.

Most of the code here for the Runner class and the TestProgram class
were originally taken from subunit and testtools respectively.

Fixes #244 for the first stacktrace outlined there, which was caused by
the test runner (which was previously outside the scope of stestr).
@mtreinish
Copy link
Owner

#256 will fix the issue outside of stestr currently. To address the first stack trace which was coming from unittest2 TypeError: missing 1 required positional argument: 'self' I wrote a separate test runner for stestr use that is based on stdlib unittest instead of using unittest2 or testtools. This will both fix the other half of the issue and actually have stestr own more of execution of the tests up until stdlib unittest is called (which should hopefully make it easier to address bugs like this in the future).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants