Can Pytest run at a pre-scheduled time?












2















I am using pytest to run my tests using python3 script like below:



pytest -s test_file.py | tee -a myoutput.log


It works. Now I would like to run this at a specific time everyday, I tried "crontab -e" from linux console but failed. I mean there is no log added to "myoutput.log" file. Can anyone please help? thanks!



42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py | tee -a myoutput.log









share|improve this question




















  • 1





    If you could perhaps add a little more detail to the "but failed" bit, that would go a long way toward helping us help you :-)

    – paxdiablo
    Nov 14 '18 at 0:50











  • What's with the /usr/bin/pytest pytest part? I'm almost sure this is the error source.

    – hoefling
    Nov 14 '18 at 9:40











  • Also, if the stdout of a command is empty, the common idiom in bash is to redirect the stderr output to stdout (command 2>&1), so if a command fails for some reasons, you are able to see the error in log. Try that if you still get an error after fixing the issue with two executables.

    – hoefling
    Nov 14 '18 at 9:45











  • /usr/bin/pytest this is the environment and "pytest -s" is the command to run the file..when I am running the command from python console instead of crontab it works fine though..

    – Hossain
    Nov 15 '18 at 0:15











  • /usr/bin/pytest looks like a path to the pytest executable. /usr/bin/pytest pytest is wrong, omit one of the two.

    – hoefling
    Nov 16 '18 at 9:37
















2















I am using pytest to run my tests using python3 script like below:



pytest -s test_file.py | tee -a myoutput.log


It works. Now I would like to run this at a specific time everyday, I tried "crontab -e" from linux console but failed. I mean there is no log added to "myoutput.log" file. Can anyone please help? thanks!



42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py | tee -a myoutput.log









share|improve this question




















  • 1





    If you could perhaps add a little more detail to the "but failed" bit, that would go a long way toward helping us help you :-)

    – paxdiablo
    Nov 14 '18 at 0:50











  • What's with the /usr/bin/pytest pytest part? I'm almost sure this is the error source.

    – hoefling
    Nov 14 '18 at 9:40











  • Also, if the stdout of a command is empty, the common idiom in bash is to redirect the stderr output to stdout (command 2>&1), so if a command fails for some reasons, you are able to see the error in log. Try that if you still get an error after fixing the issue with two executables.

    – hoefling
    Nov 14 '18 at 9:45











  • /usr/bin/pytest this is the environment and "pytest -s" is the command to run the file..when I am running the command from python console instead of crontab it works fine though..

    – Hossain
    Nov 15 '18 at 0:15











  • /usr/bin/pytest looks like a path to the pytest executable. /usr/bin/pytest pytest is wrong, omit one of the two.

    – hoefling
    Nov 16 '18 at 9:37














2












2








2








I am using pytest to run my tests using python3 script like below:



pytest -s test_file.py | tee -a myoutput.log


It works. Now I would like to run this at a specific time everyday, I tried "crontab -e" from linux console but failed. I mean there is no log added to "myoutput.log" file. Can anyone please help? thanks!



42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py | tee -a myoutput.log









share|improve this question
















I am using pytest to run my tests using python3 script like below:



pytest -s test_file.py | tee -a myoutput.log


It works. Now I would like to run this at a specific time everyday, I tried "crontab -e" from linux console but failed. I mean there is no log added to "myoutput.log" file. Can anyone please help? thanks!



42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py | tee -a myoutput.log






python-3.x scheduled-tasks pytest scheduler






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 0:55







Hossain

















asked Nov 14 '18 at 0:48









HossainHossain

588




588








  • 1





    If you could perhaps add a little more detail to the "but failed" bit, that would go a long way toward helping us help you :-)

    – paxdiablo
    Nov 14 '18 at 0:50











  • What's with the /usr/bin/pytest pytest part? I'm almost sure this is the error source.

    – hoefling
    Nov 14 '18 at 9:40











  • Also, if the stdout of a command is empty, the common idiom in bash is to redirect the stderr output to stdout (command 2>&1), so if a command fails for some reasons, you are able to see the error in log. Try that if you still get an error after fixing the issue with two executables.

    – hoefling
    Nov 14 '18 at 9:45











  • /usr/bin/pytest this is the environment and "pytest -s" is the command to run the file..when I am running the command from python console instead of crontab it works fine though..

    – Hossain
    Nov 15 '18 at 0:15











  • /usr/bin/pytest looks like a path to the pytest executable. /usr/bin/pytest pytest is wrong, omit one of the two.

    – hoefling
    Nov 16 '18 at 9:37














  • 1





    If you could perhaps add a little more detail to the "but failed" bit, that would go a long way toward helping us help you :-)

    – paxdiablo
    Nov 14 '18 at 0:50











  • What's with the /usr/bin/pytest pytest part? I'm almost sure this is the error source.

    – hoefling
    Nov 14 '18 at 9:40











  • Also, if the stdout of a command is empty, the common idiom in bash is to redirect the stderr output to stdout (command 2>&1), so if a command fails for some reasons, you are able to see the error in log. Try that if you still get an error after fixing the issue with two executables.

    – hoefling
    Nov 14 '18 at 9:45











  • /usr/bin/pytest this is the environment and "pytest -s" is the command to run the file..when I am running the command from python console instead of crontab it works fine though..

    – Hossain
    Nov 15 '18 at 0:15











  • /usr/bin/pytest looks like a path to the pytest executable. /usr/bin/pytest pytest is wrong, omit one of the two.

    – hoefling
    Nov 16 '18 at 9:37








1




1





If you could perhaps add a little more detail to the "but failed" bit, that would go a long way toward helping us help you :-)

– paxdiablo
Nov 14 '18 at 0:50





If you could perhaps add a little more detail to the "but failed" bit, that would go a long way toward helping us help you :-)

– paxdiablo
Nov 14 '18 at 0:50













What's with the /usr/bin/pytest pytest part? I'm almost sure this is the error source.

– hoefling
Nov 14 '18 at 9:40





What's with the /usr/bin/pytest pytest part? I'm almost sure this is the error source.

– hoefling
Nov 14 '18 at 9:40













Also, if the stdout of a command is empty, the common idiom in bash is to redirect the stderr output to stdout (command 2>&1), so if a command fails for some reasons, you are able to see the error in log. Try that if you still get an error after fixing the issue with two executables.

– hoefling
Nov 14 '18 at 9:45





Also, if the stdout of a command is empty, the common idiom in bash is to redirect the stderr output to stdout (command 2>&1), so if a command fails for some reasons, you are able to see the error in log. Try that if you still get an error after fixing the issue with two executables.

– hoefling
Nov 14 '18 at 9:45













/usr/bin/pytest this is the environment and "pytest -s" is the command to run the file..when I am running the command from python console instead of crontab it works fine though..

– Hossain
Nov 15 '18 at 0:15





/usr/bin/pytest this is the environment and "pytest -s" is the command to run the file..when I am running the command from python console instead of crontab it works fine though..

– Hossain
Nov 15 '18 at 0:15













/usr/bin/pytest looks like a path to the pytest executable. /usr/bin/pytest pytest is wrong, omit one of the two.

– hoefling
Nov 16 '18 at 9:37





/usr/bin/pytest looks like a path to the pytest executable. /usr/bin/pytest pytest is wrong, omit one of the two.

– hoefling
Nov 16 '18 at 9:37












1 Answer
1






active

oldest

votes


















0














I think it can be done by using cron output. eg:



42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py >> /Your-log-path.log 2>&1






share|improve this answer
























  • now the log shows: "ERROR: file not found: pytest"

    – Hossain
    Nov 28 '18 at 18:49













  • 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py >> /Your-log-path.log 2>&1 This works now. I mean I am getting the pytest output as passed/failed results but I am loosing the outputs with print command which I was able to get with "pytest -s". Any clue, please?

    – Hossain
    Nov 28 '18 at 20:00











  • finally got it working! 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py -s >> /Your-log-path.log 2>&1

    – Hossain
    Nov 28 '18 at 22:33













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291608%2fcan-pytest-run-at-a-pre-scheduled-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think it can be done by using cron output. eg:



42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py >> /Your-log-path.log 2>&1






share|improve this answer
























  • now the log shows: "ERROR: file not found: pytest"

    – Hossain
    Nov 28 '18 at 18:49













  • 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py >> /Your-log-path.log 2>&1 This works now. I mean I am getting the pytest output as passed/failed results but I am loosing the outputs with print command which I was able to get with "pytest -s". Any clue, please?

    – Hossain
    Nov 28 '18 at 20:00











  • finally got it working! 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py -s >> /Your-log-path.log 2>&1

    – Hossain
    Nov 28 '18 at 22:33


















0














I think it can be done by using cron output. eg:



42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py >> /Your-log-path.log 2>&1






share|improve this answer
























  • now the log shows: "ERROR: file not found: pytest"

    – Hossain
    Nov 28 '18 at 18:49













  • 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py >> /Your-log-path.log 2>&1 This works now. I mean I am getting the pytest output as passed/failed results but I am loosing the outputs with print command which I was able to get with "pytest -s". Any clue, please?

    – Hossain
    Nov 28 '18 at 20:00











  • finally got it working! 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py -s >> /Your-log-path.log 2>&1

    – Hossain
    Nov 28 '18 at 22:33
















0












0








0







I think it can be done by using cron output. eg:



42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py >> /Your-log-path.log 2>&1






share|improve this answer













I think it can be done by using cron output. eg:



42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py >> /Your-log-path.log 2>&1







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 12:19









Ederson BadecaEderson Badeca

884




884













  • now the log shows: "ERROR: file not found: pytest"

    – Hossain
    Nov 28 '18 at 18:49













  • 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py >> /Your-log-path.log 2>&1 This works now. I mean I am getting the pytest output as passed/failed results but I am loosing the outputs with print command which I was able to get with "pytest -s". Any clue, please?

    – Hossain
    Nov 28 '18 at 20:00











  • finally got it working! 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py -s >> /Your-log-path.log 2>&1

    – Hossain
    Nov 28 '18 at 22:33





















  • now the log shows: "ERROR: file not found: pytest"

    – Hossain
    Nov 28 '18 at 18:49













  • 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py >> /Your-log-path.log 2>&1 This works now. I mean I am getting the pytest output as passed/failed results but I am loosing the outputs with print command which I was able to get with "pytest -s". Any clue, please?

    – Hossain
    Nov 28 '18 at 20:00











  • finally got it working! 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py -s >> /Your-log-path.log 2>&1

    – Hossain
    Nov 28 '18 at 22:33



















now the log shows: "ERROR: file not found: pytest"

– Hossain
Nov 28 '18 at 18:49







now the log shows: "ERROR: file not found: pytest"

– Hossain
Nov 28 '18 at 18:49















42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py >> /Your-log-path.log 2>&1 This works now. I mean I am getting the pytest output as passed/failed results but I am loosing the outputs with print command which I was able to get with "pytest -s". Any clue, please?

– Hossain
Nov 28 '18 at 20:00





42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py >> /Your-log-path.log 2>&1 This works now. I mean I am getting the pytest output as passed/failed results but I am loosing the outputs with print command which I was able to get with "pytest -s". Any clue, please?

– Hossain
Nov 28 '18 at 20:00













finally got it working! 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py -s >> /Your-log-path.log 2>&1

– Hossain
Nov 28 '18 at 22:33







finally got it working! 42 00 * * * /usr/local/bin/pytest /data/smc/test_file.py -s >> /Your-log-path.log 2>&1

– Hossain
Nov 28 '18 at 22:33




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291608%2fcan-pytest-run-at-a-pre-scheduled-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

MGP Nordic

Alfredo Volpi