I have a script call run_test.py, here's the content:-
if __name__ == '__main__':
nose.main(argv=sys.argv)
Running all my tests is as simple as doing this:
run_test.py unittests/test_*.py
I'm trying to now incorperate the output reporting for this into teamcity.
I'm referring to this https://github.com/JetBrains/teamcity-messages
I tried changing all my unittests/test_*.py program following the documentation. It works if running the test individually like this:-
unittest/test_one.py
But it does not work when running it thru nose, like this:
run_test.py unittest/test_one.py
According to the documentation link, it says that nose reporting is enabled automatically under TeamCity build. I don't quite get what that means.
Is there anything that i'm missing out here?
Any help is greatly appreciated. Thanks.
have a look at the xunit plugin of nose.
it will generate an xml file with the results => which jenkins and teamcity can use.
some documentation for teamcity
this post tells you how to enable the plugin in your test script
if __name__ == '__main__':
argv = sys.argv[:]
argv.insert(1, "--with-xunit")
nose.main(argv=argv)
I finally found out the way to achieve that.
Here's what i modified in my run_test.py
#!/usr/bin/env python
import os
import sys
import unittest
from teamcity import is_running_under_teamcity
from teamcity.unittestpy import TeamcityTestRunner
loader = unittest.TestLoader()
start_dir = sys.argv[1]
suite = loader.discover(start_dir, pattern='test_*.py')
#runner = unittest.TextTestRunner()
runner = TeamcityTestRunner(verbosity=2)
runner.run(suite)
Related
I am trying to execute test suit by importing class from another file.
I have file list as below -
enter image description here
I am using below -
import unittest
import HTMLTestRunner
from Enhancement.Exercise18_WriteExcel import TestEx18
from UnitTest.Exercise14_OrderFood import TestEx14
if __name__ == "__main__":
# import sys;sys.argv = ['', 'Test.testName']
unittest.main()
# get all tests from Login and SignUp class
tc1 = unittest.TestLoader().loadTestsFromTestCase(TestEx18)
tc2 = unittest.TestLoader().loadTestsFromTestCase(TestEx14)
# create a test suite combining tc1 and tc2
test_suite = unittest.TestSuite([tc1, tc2])
# run the suite
unittest.TextTestRunner(verbosity=1).run(test_suite)
#unittest.main(testRunner=HTMLTestRunner.HTMLTestRunner(output="demo/reports"))
But getting error -
enter image description here
Kindly advise how can I resolve this issue.
Take a look at the answer found here ==> https://stackoverflow.com/a/28224295/16879293
basically, you have 2 options, one would be to add your Enhancement to the PYTHONPATH, or you can simply add to your code :
import sys
sys.append("..")
Run the same command from /path/to/Selenium_Practice/ folder (and not /path/to/Selenium_Practice/Reporting/ folder)
My project structure is as below. I couldn't find enough data from the twisted documentation
-rolling
->roll
->__init__.py
->rollserver.py
->twisted
->plugins
->roll_plugin.py
My roll_plugin.py looks like this-
from zope.interface import implementer
from twisted.plugin import IPlugin
from twisted.application.service import IServiceMaker
from utils.annon_edro import Options, GPMSBridgeService
from roll..rollserver import RollFactory
#implementer(IServiceMaker, IPlugin)
class MyServiceMaker(object):
tapname = "roll"
description = 'Open the great door of roll for default'
options = Options
def makeService(self, options):
return internet.TCPServer(8999, RollFactory())
serviceMaker = MyServiceMaker()
I ran twistd --help I do not see the sub command there.
Whilst this code runs fine with Python2 but not with Python3.10.
What am I doing wrong here?
Is there any way we debug twistd code?
The directory path was missing in sys.path, adding it worked for me.
I am trying to manage the results of machine learning with mlflow and hydra.
So I tried to run it using the multi-run feature of hydra.
I used the following code as a test.
import mlflow
import hydra
from hydra import utils
from pathlib import Path
import time
#hydra.main('config.yaml')
def main(cfg):
print(cfg)
mlflow.set_tracking_uri('file://' + utils.get_original_cwd() + '/mlruns')
mlflow.set_experiment(cfg.experiment_name)
mlflow.log_param('param1',5)
# mlflow.log_param('param1',5)
# mlflow.log_param('param1',5)
with mlflow.start_run() :
mlflow.log_artifact(Path.cwd() / '.hydra/config.yaml')
if __name__ == '__main__':
main()
This code will not work.
I got the following error
Exception: Run with UUID [RUNID] is already active. To start a new run, first end the current run with mlflow.end_run(). To start a nested run, call start_run with nested=True
So I modified the code as follows
import mlflow
import hydra
from hydra import utils
from pathlib import Path
import time
#hydra.main('config.yaml')
def main(cfg):
print(cfg)
mlflow.set_tracking_uri('file://' + utils.get_original_cwd() + '/mlruns')
mlflow.set_experiment(cfg.experiment_name)
mlflow.log_param('param1',5)
# mlflow.log_param('param1',5)
# mlflow.log_param('param1',5)
with mlflow.start_run(nested=True) :
mlflow.log_artifact(Path.cwd() / '.hydra/config.yaml')
if __name__ == '__main__':
main()
This code works, but the artifact is not saved.
The following corrections were made to save the artifacts.
import mlflow
import hydra
from hydra import utils
from pathlib import Path
import time
#hydra.main('config.yaml')
def main(cfg):
print(cfg)
mlflow.set_tracking_uri('file://' + utils.get_original_cwd() + '/mlruns')
mlflow.set_experiment(cfg.experiment_name)
mlflow.log_param('param1',5)
# mlflow.log_param('param1',5)
# mlflow.log_param('param1',5)
mlflow.log_artifact(Path.cwd() / '.hydra/config.yaml')
if __name__ == '__main__':
main()
As a result, the artifacts are now saved.
However, when I run the following command
python test.py model=A,B hidden=12,212,31 -m
Only the artifact of the last execution condition was saved.
How can I modify mlflow to manage the parameters of the experiment by taking advantage of the multirun feature of hydra?
MLFlow is not officially supported by Hydra. At some point there will be a plugin that will make this smoother.
Looking at the errors you are reporting (and without running your code):
One thing that you can try to to use the Joblib launcher plugin to get job isolation through processes (this requires Hydra 1.0.0rc1 or newer).
What you are observing is due to the interaction between MLFlow and Hydra. As far as MLflow can tell, all of your Hydra multiruns are the same MLflow run!
Since both frameworks use the term "run", I will need to be verbose in the following text. Please bear with me.
If you didn't explicitly start a MLflow run, MLflow will do it for you when you do mlflow.log_params or mlflow.log_artifacts. Within a Hydra multirun context, it appears that instead of creating a new MLflow run for each Hydra run, the previous MLflow run is inherited after the first Hydra run. This is why you would get this error where MLflow thinks you are trying to update parameter values in logging: mlflow.exceptions.MlflowException: Changing param values is not allowed.
You can fix this by wrapping your MLFlow logging code within a with mlflow.start_run() context manager:
import mlflow
import hydra
from hydra import utils
from pathlib import Path
#hydra.main(config_path="", config_name='config.yaml')
def main(cfg):
print(cfg)
mlflow.set_tracking_uri('file://' + utils.get_original_cwd() + '/mlruns')
mlflow.set_experiment(cfg.experiment_name)
with mlflow.start_run() as run:
mlflow.log_params(cfg)
mlflow.log_artifact(Path.cwd() / '.hydra/config.yaml')
print(run.info.run_id) # just to show each run is different
if __name__ == '__main__':
main()
The context manager will start and end MLflow runs properly, preventing the issue from occuring.
Alternatively, you can also start and end an MLFlow run manually:
activerun = mlflow.start_run()
mlflow.log_params(cfg)
mlflow.log_artifact(Path.cwd() / '.hydra/config.yaml')
print(activerun.info.run_id) # just to show each run is different
mlflow.end_run()
This is related to the way you defined your MLFlow run. You use log_params and then start_run, so you have two concurrent runs of mlflow which explains the error. You could try getting rid of the following line in your first code sample and see what happens
mlflow.log_param('param1',5)
This might be really stupid, but I can't get it to work...
I'm want to use the such DLS in nose2 with python 2.7 in Linux.
I'm trying out the beginning of the example from the documentation http://nose2.readthedocs.org/en/latest/such_dsl.html (see code below) but it doesn't run the tests, no matter how I launch it from the command line.
My file is called test_something.py, it's the only file in the directory.
I've tried running from the command line with >> nose2 and >> nose2 --plugin nose2.plugins.layers, but I always get Ran 0 tests in 0.000s. With >> nose2 --plugin layers I get ImportError: No module named layers.
How am I supposed to run this test from the command line??
Thanks!
Code below:
import unittest
from nose2.tools import such
with such.A("system with complex setup") as it:
#it.has_setup
def setup():
print "Setup"
it.things = [1]
#it.has_teardown
def teardown():
print "Teardown"
it.things = []
#it.should("do something")
def test():
print "Test"
assert it.things
it.assertEqual(len(it.things), 1)
DOH!
I forgot to add it.createTests(globals()) at the end of the file!
I'm new to debugging flask with pycharm, so hopefully nothing I ask is too trivial.
I have two files, code/__init__.py and code/runserver.py.
The __init__.py file is where my Flask app is initialized, meaning that is where the statement
app = Flask(__name__)
occurs.
In the runserver.py file is where I have the statement:
if __name__ == '__main__':
main()
The runserver imports the app in the following manner:
from code import app, __app_name__, __version__
Inside of the main function are a number of parser.addoption commands and then ultimately
def main():
parser = OptionParser()
parser.add_option("-d", "--debug", action="store_true",
default=app.config.get('DEBUG', True),
dest="debug", help="Turn on debugging")
(options, args) = parser.parse_args()
app.run(debug=options.debug, host=options.address, port=options.port)
In this case what would my entry point for debugging the application be?
I assumed it would be runserver.py but when I attempt to debug this I get the response of
ImportError: No module named code
If however I run it like
python ${BASE}/code/runserver.py
I don't have any issues.
Several moments
1) If you want to debug with PyCharm you should set default debugger to False (app.debug)
2) In PyCharm you should not use /code/ folder as root, because in this manner no code is visible by import
If you make codeProject/code/ and open codeProject as root in pycharm and then run codeProject/runserver.py or codeProject/code/runserver.py everything should be fine