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

dev: Cannot run tests from command-line #1160

Closed
ValueRaider opened this issue Nov 10, 2022 · 3 comments
Closed

dev: Cannot run tests from command-line #1160

ValueRaider opened this issue Nov 10, 2022 · 3 comments

Comments

@ValueRaider
Copy link
Collaborator

ValueRaider commented Nov 10, 2022

python -m tests.ticker

This used to work with old test code containing just a simple unittest.main(), but fails with new suite. Am I being dumb?

Traceback (most recent call last):
File "/usr/lib64/python3.10/unittest/case.py", line 366, in init
testMethod = getattr(self, methodName)
AttributeError: 'TestTicker' object has no attribute 'Test ticker'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib64/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib64/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "yfinance-tz-cache/tests/ticker.py", line 288, in
runner.run(suite())
File "yfinance-tz-cache/tests/ticker.py", line 279, in suite
suite.addTest(TestTicker('Test ticker'))
File "/usr/lib64/python3.10/unittest/case.py", line 371, in init
raise ValueError("no such test method in %s: %s" %
ValueError: no such test method in <class 'main.TestTicker'>: Test ticker

@fredrik-corneliusson

@ValueRaider ValueRaider changed the title Cannot run tests from command-line dev: Cannot run tests from command-line Nov 10, 2022
@fredrik-corneliusson
Copy link
Contributor

That has never worked for me.
I've had to run it using "unittest" module.

Try running it like this instead:
Whole suite:
python -m unittest tests.ticker

Specific test class:
python -m unittest tests.ticker.TestTicker

How to run the tests should probably be documented in a CONTRIBUTING.md file.

There is an issue with the cleanup code that should remove the CachedSession but it does not effect the tests, but annoying and should be looked in to.

@fredrik-corneliusson
Copy link
Contributor

Regarding the issue with removing temp-folder I think the whole issue can be circumvented by not persisting on disk but instead initialize session on class object instead of instance setup and teardown

class TestTicker(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.session = requests_cache.CachedSession()

    @classmethod
    def tearDownClass(cls):
        cls.session.close()

fredrik-corneliusson added a commit to fredrik-corneliusson/yfinance-tz-cache that referenced this issue Nov 10, 2022
@fredrik-corneliusson
Copy link
Contributor

This is merged into dev, so should be fixed.

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

No branches or pull requests

2 participants