我想将一个命令行arg(一个表示地址的字符串)传递给我基于位置的服务的集成测试。这些测试是从测试运行器Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.util.Optional
at java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469)
at java.util.Collections$ReverseComparator2.compare(Collections.java:5178)
at java.util.Comparator.lambda$thenComparing$36697e65$1(Comparator.java:216)
at javax.swing.DefaultRowSorter.compare(DefaultRowSorter.java:968)
at javax.swing.DefaultRowSorter.access$100(DefaultRowSorter.java:112)
at javax.swing.DefaultRowSorter$Row.compareTo(DefaultRowSorter.java:1376)
at javax.swing.DefaultRowSorter$Row.compareTo(DefaultRowSorter.java:1366)
at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:320)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:188)
at java.util.Arrays.sort(Arrays.java:1246)
at javax.swing.DefaultRowSorter.sort(DefaultRowSorter.java:607)
at javax.swing.DefaultRowSorter.setSortKeys(DefaultRowSorter.java:319)
at javax.swing.DefaultRowSorter.toggleSortOrder(DefaultRowSorter.java:480)
at javax.swing.plaf.basic.BasicTableHeaderUI$MouseInputHandler.mouseClicked(BasicTableHeaderUI.java:112)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
at java.awt.Component.processMouseEvent(Component.java:6536)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
调用的。
run_tests.py
这是我的集成测试子类的基类。现在我已经硬编码了一个地址。我想将cmd-line arg分配给import argparse
import unittest
import mycity.test.integration_tests.test_snow_emergency_parking as snow_parking
import mycity.test.integration_tests.test_trash_intent as trash_intent
import mycity.test.integration_tests.test_unhandled_intent as unhandled_intent
import mycity.test.integration_tests.test_get_alerts as get_alerts
import mycity.test.unit_tests.test_finder_csv as finder_csv
import mycity.test.unit_tests.test_mycity_controller as my_controller
import mycity.test.unit_tests.test_address_utils as address_utils
import mycity.test.unit_tests.test_google_maps_utils as g_maps_utils
import mycity.test.unit_tests.test_csv_utils as csv_utils
import mycity.test.unit_tests.test_gis_utils as gis_utils
TEST_CASES = [ my_controller.MyCityControllerUnitTestCase,
g_maps_utils.TestGoogleMapsUtilities,
address_utils.AddressUtilitiesTestCase,
csv_utils.CSVUtilitiesTestCase,
gis_utils.GISUtilitiesTestCase,
finder_csv.FinderCSVTestCase,
get_alerts.GetAlertsTestCase,
trash_intent.TrashDayTestCase,
unhandled_intent.UnhandledIntentTestCase,
snow_parking.SnowEmergencyTestCase
]
def load_tests():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
for test_case in TEST_CASES:
suite.addTests(loader.loadTestsFromTestCase(test_case))
return suite
if __name__ == "__main__":
test_suite = load_tests()
runner = unittest.TextTestRunner()
runner.run(test_suite)
。
self.request._session_attributes[key]
答案 0 :(得分:0)
您需要一个参数解析器
这是一个简单的例子:
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='integration tests')
parser.add_argument('--address', help='address', required=True,
help="address as string")
args = parser.parse_args()
address = args.address
随意查看argparse documentation(Python 3)