{"id":11587,"date":"2020-10-18T14:51:10","date_gmt":"2020-10-18T12:51:10","guid":{"rendered":"http:\/\/flaven.fr\/?p=11587"},"modified":"2026-09-16T10:10:23","modified_gmt":"2026-09-16T08:10:23","slug":"python-randomization-e2e-its-all-about-random-and-some-good-reasons-to-learn-and-leverage-on-python","status":"publish","type":"post","link":"https:\/\/flaven.fr\/2020\/10\/python-randomization-e2e-its-all-about-random-and-some-good-reasons-to-learn-and-leverage-on-python\/","title":{"rendered":"Python, Randomization, E2E &#8211; it&#8217;s all about Random and some good reasons to learn and leverage on Python"},"content":{"rendered":"<p>Order is a very relative notion, it is specific for each of us. &#8220;The world is my representation&#8221; as Arthur &#8220;Chop&#8221; Schopenhauer says.  At the same time, experience teaches us &#8220;Every cloud has a silver lining&#8221; so modestly I discovered that a relative &#8220;disorder&#8221; is often more efficient than an absolute &#8220;order&#8221;. Right? Ooh slow down a bit! It is not an easy-peasy Q\/A!<\/p>\n<p>For sure, you can ask yourself why such interrogations are part of a so called post dedicated to Python. Well, first of all, it make sense for me for several reasons:<\/p>\n<p>Never bad to introduce some philosophy in programming practice. Personally, it reconciles two of my favorite hobbies (bad programming &#038; cheap philosophy) to one : headache! More serioulsy, these thoughts come from a practical and real-world experience.<\/p>\n<p>Let me tell you the story: after a long, long aging process, as a PO, I achieved to build a robust testing strategy with CodeceptJS for a backoffice! But then I discovered that the e2e sequential execution of the suite created a bias (let&#8217;s called them errors). OMG! Then I was wondering how to introduce randomization inside the testing suite execution in order to reduce this bias to the maximum. The purpose is to avoid the false positive nightmare!<\/p>\n<p>Meanwhile, in a completely chaotic, confused, disordered, disorganized, topsy-turvy, helter-skelter, pell-mell, upside-down, higgledy-piggledy, hugger-mugger, harum-scarum, snafu, slipshod, unplanned, erratic, strayed, hit-and-miss, incidental, spontaneous, uncoordinated, willy-nilly, devil-may-care, unpremeditated, reckless, cockeyed, hit-and-miss, fluky, incidental&#8230; anarchic way, I am learning advanced Python techniques (NLP, facial recognition &#8230;) but also fundamentals like the difference between a &#8220;tuple&#8221; and a &#8220;dictionary&#8221;. <b>So it was logic that Python popped up in my mind to bring this randomness, given the complexity of doing the same thing in Bash, a language that I am far from mastering!<\/b><\/p>\n<p><b>Incidentally, this experiment proves me that Python is: <\/b> <\/p>\n<ul>\n<li><b>Easy to read:<\/b> Python is easy to read and most of the language makes sense at a glimpse. This makes finding issues a lot easier than more complicated languages.<\/li>\n<li><b>Portability:<\/b> Python runs on many platforms and systems, meaning your programs can reach a wider audience. It can easily replace Bash or Ruby of instance.<\/li>\n<\/ul>\n<p>Two qualities that gave Python a serious advantage in what I am looking for: to create on-demand order or disorder \ud83d\ude42<\/p>\n<ul>\n<li>Order: when it comes to browsing, summarizing and indexing hundreds of texts in order to store them in a database itself MySQL and\/or NoSQL.<\/li>\n<li>Disorder: when it comes to run tests in parallel, for example, and thereby overcome a bias linked to a sequential execution.<\/li>\n<\/ul>\n<p><b>Oddly, sometimes, Disorder proves to be more efficient and effective than Order.<\/b><\/p>\n<p>So, this post presents my quick researches on how-to handle random in Python. Having in mind that the final objective is to load randomly testing files that achieve a complete Backoffice&#8217;s assessment without increasing errors into the process.<\/p>\n<p><b>By the way, it reveals a third and fourth Python qualities:<\/b> <\/p>\n<ul>\n<li><b>Increasing productivity:<\/b> how much work you can accomplish in a given time with few lines of code.<\/li>\n<li><b>Relieving Boring Stuff in Bullshit Jobs:<\/b> Thanks to Al Sweigart and David Graeber to have enabled me to create this &#8220;tuna-mayo-sandwich&#8221; concept.<\/li>\n<\/ul>\n<p>So, now, let&#8217;s move on and show some code&#8230;<\/p>\n<h2>The code for this POC<\/h2>\n<p>A mix of files that show some concepts explained above. Most of them should end to the bin but sometimes I need to refresh my own memory so I made up a post with it.<\/p>\n<p><b><a href=\"https:\/\/github.com\/bflaven\/BlogArticlesExamples\/tree\/master\/python_random_is_all_about\" target=\"_blank\" rel=\"noopener noreferrer\">You can get all the files on my github account in python_random_is_all_about<\/a><\/b><\/p>\n<pre lang=\"bash\">\r\n# Get to the correct directory\r\ncd \/Users\/brunoflaven\/Documents\/02_copy\/_random_is_all_about\/\r\n\r\n# Shuffling array in python\r\nshuffle_array.py\r\n\r\n\r\n# Working with Tuple\r\ndepot_command_python_1.py\r\n\r\n# Introducing shuffle in array\r\ndepot_command_python_3.py\r\n\r\n# Output python version of the system\r\ndepot_command_python_4.py\r\n\r\n# Working with Dictionaries\r\ndepot_command_python_5.py\r\n\r\n# Using bash to launch python\r\nexecute_python_from_bash_1.sh\r\nexecute_python_from_bash_2.sh\r\n\r\n# Model for Basic Automation with Python extracted from Book Redefining a testing automation strategy for a P.O. with CodeceptJS & WordPress (The continuous learning trilogy Book 3) (English Edition) \r\nlaunch_scripts_with_python_3.py\r\n\r\n# Attempts in Randomization\r\nrandom_array_1.sh\r\nrandom_array_2.py\r\nrandom_array_2.sh\r\nrandom_array_3.py\r\nrandom_array_4.py\r\nrandom_array_5.py\r\n\r\n# Encoding issue\r\nutf8_shebang.py\r\n\r\n# A directory with a demonstration applied for the E2E testing suite, but not the suite itself\r\ntest_platform\r\n<\/pre>\n<h2>Which Python ?<\/h2>\n<p>Most of the time I am using python from Anaconda but from now on, I started to use: <\/p>\n<ol>\n<li>Python distributed (python2) with Mac<\/li>\n<li>but also another Python (python3) installed with the help of Homebrew<\/li>\n<\/ol>\n<p>The fact that Python replace my poor Bash notions and enable me to scale up at the same time my abilities to do things and speed up my Python&#8217;s learning process. For instance, the python&#8217;s ability to randomize or shuffle elements is very easy to catch and then code. So, my idea was to launch a bash (.bat, yes I am sometime on Windows) that launch a Python script (.py) that will launch a random shuffle of CPJS scripts e2e suite (a bunch of .js files). Russian doll game for PO.<\/p>\n<p>There are plenty of resources about this Python version issue. I always forget to note down precisely what was helpful and what was not. Anyway, when you&#8217;ll be handling to Python versions on your computer, you may find useful these commands.<\/p>\n<pre lang=\"bash\">\r\n\r\n# Some commands to determine the Python's version\r\n\r\npython --version\r\n# Output: Python 2.7.10\r\nwhich python\r\n# \/usr\/bin\/python\r\n\r\n\r\npython3 --version\r\n# Output: Python 3.7.7\r\nwhich python3\r\n# \/usr\/local\/bin\/python3\r\n\r\n\r\n# So, you can decide to execute your Python script whether with the version 2 or 3 of Python.\r\n\r\npython3 myscript_in_python.py\r\n\r\npython myscript_in_python.py\r\n\r\n<\/pre>\n<p>The other thing is that I am not always writting in english so I have start to use only Python 3 as Python 3 come by default in UTF-8 and declare also the encoding. Period.<\/p>\n<pre lang=\"python\">\r\n#!\/usr\/bin\/python\r\n# -*- coding: utf-8 -*-\r\n#\r\n<\/pre>\n<h2>Read more<\/h2>\n<ul>\n<li>The right and wrong way to set Python 3 as default on a Mac<br \/><a href=\"https:\/\/opensource.com\/article\/19\/5\/python-3-default-mac\">https:\/\/opensource.com\/article\/19\/5\/python-3-default-mac<\/a><\/li>\n<li>Python Shuffle List: A Step-By-Step Guide<br \/><a href=\"https:\/\/careerkarma.com\/blog\/python-shuffle-list\/\"target=\"_blank\">https:\/\/careerkarma.com\/blog\/python-shuffle-list\/<\/a><\/li>\n<li>Python | Ways to shuffle a list<br \/><a href=\"https:\/\/www.geeksforgeeks.org\/python-ways-to-shuffle-a-list\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.geeksforgeeks.org\/python-ways-to-shuffle-a-list\/<\/a><\/li>\n<li>Python random.shuffle() function to shuffle list<br \/><a href=\"https:\/\/pynative.com\/python-random-shuffle\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/pynative.com\/python-random-shuffle\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Order is a very relative notion, it is specific for each of us. &#8220;The world is my representation&#8221; as Arthur &#8220;Chop&#8221; Schopenhauer says. At the&hellip; <\/p>\n<p class=\"text-center\"><a href=\"https:\/\/flaven.fr\/2020\/10\/python-randomization-e2e-its-all-about-random-and-some-good-reasons-to-learn-and-leverage-on-python\/\" class=\"more-link\">Continue reading &rarr; <span class=\"screen-reader-text\">Python, Randomization, E2E &#8211; it&#8217;s all about Random and some good reasons to learn and leverage on Python<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":11589,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"bf_ai_meta_description":"Master Python's randomization tools for efficient end-to-end testing. Enhance outcomes with strategic disorder in coding practices.","bf_ai_og_title":"Python Randomization E2E","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3438,3437,3444,3447,3449],"tags":[2532,2603,2605,2597,2598,2593,2604,2590,1697,2600,3491,2589,2591,2594,2596,2592,2606,2607,2587,2595,2588,2601,2599,3508,2602],"class_list":["post-11587","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-machine-learning","category-business-case-studies","category-programming-databases","category-technology-trends","category-tutorials-how-to","tag-anaconda","tag-array","tag-basic-automation","tag-boring-stuff","tag-bullshit-jobs","tag-codeceptjs","tag-dictionaries","tag-disorder","tag-experience","tag-graeber","tag-nosql","tag-order","tag-philosophy","tag-practical","tag-productivity","tag-programming","tag-python2","tag-python3","tag-randomization","tag-real-world","tag-schopenhauer","tag-shuffling","tag-sweigart","tag-test-automation","tag-tuple"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3Vuhl-30T","jetpack_featured_media_url":"https:\/\/flaven.fr\/wp-content\/uploads\/2020\/10\/random_is_all_about_b.jpg","_links":{"self":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/11587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/comments?post=11587"}],"version-history":[{"count":16,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/11587\/revisions"}],"predecessor-version":[{"id":11909,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/11587\/revisions\/11909"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/media\/11589"}],"wp:attachment":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/media?parent=11587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/categories?post=11587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/tags?post=11587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}